Returning JavaScript objects to the Clr


It is normally not possible to pass JavaScript objects to the Clr. The only ways to do this are to use the JintEngine.Run(..., false) function, or to use the ExecutionVisitor class directly. In all other cases, trying to pass a JavaScript object will result in a null value, which is completely useless.

I would like to be able to transparently pass JS objects using return, property setters and function call arguments. I suggest to simply return the raw JsObject object instead, without any conversion. This will at least provide a more flexible way to pass objects. A better solution may be to use a wrapper class, which converts the JsObject values on-demand.

Other than that, I really like Jint. It's great to have lightweight C-style scripting support in .Net! Thank you!
Closed Oct 3, 2014 at 6:43 PM by sebastienros
Jint has been rewritten and this issue should be fixed in the new version. Please check it on https://github.com/sebastienros/jint or on using the nuget package here: https://www.nuget.org/packages/Jint/


sebastienros wrote Sep 26, 2010 at 4:09 PM

Actually most of returned values are not null if you use the default Run with unwrap==true. For instance strings, integers, functions are converted. And otherwise you can still specify Run(script, false), I don't understand your concern on this point.

UFO wrote Sep 26, 2010 at 7:39 PM

I'd like to be able to use ExecuteFunction as well.

Also, it's currently not possible to use .Net collections like this:
var b = { a: 'value' };
var l = new System.Collections.ArrayList();

Or to use objects as arguments to any other call to a .Net function. Some way to explicitly convert/cast/pass a JavaScript object as a .Net JsObject would also help a lot.