Hi,
I'm trying to create a minimal JavaScript shell that has a global
load() function. I would like to add properties to the load() function
object. I have the following code
public class Shell extends ScriptableObject {
private Context cx;
public Shell() throws Exception {
cx = Context.enter();
cx.initStandardObjects(this);
String[] names = {"load"};
defineFunctionProperties(names,
Shell.class,
ScriptableObject.DONTENUM);
ScriptableObject loadObject =
(ScriptableObject)ScriptableObject.getProperty(this, "load");
loadObject.defineProperty("prop",
Shell.class,
0);
}
public String getProp() {
return "the prop value";
}
// definition of load function etc all of which seems to work...
}
When I run the following JavaScript in this shell
load.prop;
I see the following error message
java.lang.IllegalArgumentException: object is not an instance of declaring class
org.mozilla.javascript.WrappedException: Wrapped
java.lang.IllegalArgumentException: object is not an instance of
declaring class (/Users/peter/svn/harmony/harmonyShell/foo.js#8)
at
org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1757)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:170)
at
org.mozilla.javascript.ScriptableObject.getImpl(ScriptableObject.java:1949)
at
org.mozilla.javascript.ScriptableObject.get(ScriptableObject.java:280)
at
org.mozilla.javascript.IdScriptableObject.get(IdScriptableObject.java:385)
at
org.mozilla.javascript.ScriptableObject.getProperty(ScriptableObject.java:1544)
at
org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1375)
at
org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1364)
at
org.mozilla.javascript.gen.c1._c0(/Users/peter/svn/harmony/harmonyShell/foo.js:8)
at
org.mozilla.javascript.gen.c1.call(/Users/peter/svn/harmony/harmonyShell/foo.js)
at
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
at
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
at
org.mozilla.javascript.gen.c1.call(/Users/peter/svn/harmony/harmonyShell/foo.js)
at
org.mozilla.javascript.gen.c1.exec(/Users/peter/svn/harmony/harmonyShell/foo.js)
at org.mozilla.javascript.Context.evaluateString(Context.java:1196)
at Shell.processFile(Unknown Source)
at Shell.doRequire(Unknown Source)
at Shell.requireFile(Unknown Source)
at Shell.main(Unknown Source)
Caused by: java.lang.IllegalArgumentException: object is not an
instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:155)
... 17 more
Any ideas what I have done wrong?
Thank you,
Peter
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino