Thanks for the reply. I understand that the constructor is necessary for the JS environment to create the object. But I already have the object created and just want to add it to the JS environment. Either by adding a new variable that references it or by returning a reference to it from a native function call.
Thanks! Dave -----Original Message----- From: dev-tech-js-engine-rhino-bounces+davidparks21=yahoo....@lists.mozilla.org [mailto:dev-tech-js-engine-rhino-bounces+davidparks21=yahoo....@lists.mozill a.org] On Behalf Of Mike Tardif Sent: Monday, February 23, 2009 8:42 AM To: [email protected] Subject: Re: Not doing something right On Feb 20, 1:34 pm, "David Parks" <[email protected]> wrote: > I'm either doing something wrong or don't understand the functionality of > Rhino here. > > I am creating an object in Java and trying to pass it to the JS environment > via another JS function. I set up this simplified example to try to > understand the functionality: > > Scriptable jsObject = Context.toObject(new ExampleJSClass(), instanceScope); > instanceScope.put("obj0", instanceScope, jsObject); > cx.evaluateString(instanceScope, "obj0.fun1();", "test", 1, null); > > static class ExampleJSClass extends ScriptableObject { > public void jsConstructor(){ } > public String getClassName(){ return "ExampleJSClass"; } > public void jsFunction_fun1(){ } > } > > Can someone help me understand what I need to do to make this work, or what > I'm doing wrong? This example throws the exception: > org.mozilla.javascript.EcmaError: TypeError: Cannot find default value for > object. (test#1) It is my understanding that you need a ctor -- see below static class ExampleJSClass extends ScriptableObject { public void jsConstructor(){ } public void ExampleJSClass() { } // must match the signature of your jfConstructor public String getClassName(){ return "ExampleJSClass"; } public void jsFunction_fun1(){ } } Cheers, Mike _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
