Hello,
I'm having trouble with a "cannot find function" error when I use the
Rhino 1.6R7 jar file instead of the older 1.6R5. But I need the new
E4X functionality in 1.6R7, so I am stuck. I hope someone in this
group can help. I have distilled the problem to a (relatively) small
code fragment below.
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Scriptable;
public class SimpleRhinoEmbedding {
private static final String FUNCTION_STRING = "function f (x)
{ return x.method2();};";
public static void main (String[] args) {
Context cx = Context.enter();
try {
Scriptable sharedScope = cx.initStandardObjects();
Function aScript = cx.compileFunction (sharedScope,
FUNCTION_STRING, "test function", 1, null);
Scriptable newScope = cx.newObject (sharedScope);
newScope.setPrototype (sharedScope);
newScope.setParentScope (null);
Object[] arguments = { new Derived () };
Object result = aScript.call (cx, newScope, null,
arguments);
System.out.println ("Result: " + Context.jsToJava (result,
String.class));
} finally {
Context.exit();
}
}
}
class Base {
public String method1 () {
return "method1";
};
}
class Derived extends Base {
public String method1 () {
return "Derived method1";
};
public String method2 () {
return "method2";
};
}
When I run this code with the 1.6R5 version, it correctly outputs the
string "Result: method2". But when I run it with the 1.6R7 version, it
complains that it cannot find the function method2. I am sure there is
a gap in my understanding here, and I would greatly appreciate someone
clarifying this.
Thanks in advance,
Sridhar
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino