Return native value from clr function

Sep 7, 2010 at 7:26 PM
Edited Sep 7, 2010 at 7:26 PM

I've written some extension classes to Jint that allow me to simply write CLR classes and wrap them up and use them in a script where allow clr is false. The significant problem I'm having is when these classes return other CLR objects as the JintEngine normally handles initializing the instances of my wrapped CLR object where as when the wrapped CLR object is returning a new reference it passes a CLR object unwrapped to the JintEngine. 

I've tried using JsObject to wrap even basic values such as numbers and they still see the return as a CLR object instead of a native js value. Is there some way to properly intialize a reference value in the js engine from the CLR that can be returned to the JintEngine via a return statement in the CLR.

 

For example, this will throw an exception by attempting to interact with a CLR reference when AllowCLR is false.

 

[ScriptVisible]
public SquareValue(int a)
{
     return new JsObject(a * a);
}

 

Sep 8, 2010 at 4:32 AM

Never mind, turns out I wasn't calling ExecutionVisitor.Return when invoking my method nor properly handing and initializing static properties