This project is read-only.

Passing .Net object instance into JavaScript runtime

Nov 25, 2011 at 12:01 PM

I've downloaded the spidermonkey-dotnet binaries and I am trying to use from .Net.  Is it possible to create an object in .Net first then pass that instance through as a preconfigured object to the javascript runtime so I can call methods on it etc. from inside JavaScript?



Nov 26, 2011 at 7:51 PM

Considering exposing both that type, and a factory object to instantiate that type.  The factory would initialize the instance values for you on the C# side. 

Nov 28, 2011 at 10:45 AM

Thanks for the reply.


That would probably work, though I expect end users to be writing the scripts without intimate knowledge of the program's workings.  The C# could prepend the script with the factory call to make sure the object is available straight away to users.  It means all preconfigured variables would have to be accessed through that object which might complicate the calling syntax for the users as oppose to just some predefined variables with a well known name.


I've been looking at as it can work with preconfigured objects but it seems to have been abandoned by it's author.

Dec 14, 2011 at 6:28 PM

Use SMScript::CreateObject this method takes a .Net object instance and will create it in javascript. CreateObject side-effect is that the object is GC locked. Make sure to use DestroyObject on the .net object when you are finished with it.

Dec 14, 2011 at 7:07 PM

Thanks for taking the time to post but I ended up going for IronPython as it was a lot easier to use for my needs.