I'm trying to run JSLint using Rhino, but I've encountered a problem that has somewhat stumped me. How can I create a 'real' array from Java? Here's what I've been trying:
Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects();
String src = "function f(a) { return a instanceof Array; };";
cx.evaluateString(scope, src, "<src>", 0, null);
Function f = (Function) scope.get("f", scope);
Object[] fArgs = new Object[]{ new NativeArray(0) };
Object result = f.call(cx, scope, scope, fArgs);
System.out.println(Context.toString(result));
Context.exit();
But result is false. What am I doing wrong?
P.S.: Since I don't want to mess with JSLint's source, it is essential that I can create an object that passes the "instanceof" test.
cx.newArray(scope, 0)
instead. Constructing a NativeArray object directly won't work, 'cause it still needs to have its prototype set to the value of "Array.prototype" from your scope. newArray() will take care of all of that.
Attila.
That did it. Thank you very much.