Constructing jsArray?

Jul 4, 2011 at 9:48 PM
Edited Jul 4, 2011 at 11:18 PM

How would I go about constructing an javascript array in the host CLR? I don't want to use run("[]"), but I can't seem to find a way to elegantly add elements either. Is there a conversion function somewhere?


Nvm, after doing some searching, I found out the 'Global' property I wanted was in JintEngine all along. I found it by accident after attempting to access the visitor instance member using reflection. Silly me :(

For anyone who wants to know how to do this, you do it like this:


var c = new Jint.JintEngine();
var myarray = c.Global.ArrayClass.New();
c.SetParameter("foo", myarray);

Oh yeah and another thing, this is how I'm able to manually construct arrays of objects, looking at SetParameter you have to use JintEngine.Global.WrapClr to expose your objects like in SetParameter:


public class test
	public void foobar(){ }
test s = new test();
Jint.JintEngine je = new Jint.JintEngine();
	.concat(je.Global, new Jint.Native.JsInstance [] { je.Global.WrapClr(s) }));