Hi,

I've been playing around with Rhino to build some JUnitEE tests for some 
JavaScript code that uses jQuery and CometD. I could successfully load the 
env-js library (which emulates the browser stuff), jQuery and some other JS 
libraries we require. In particular the Cometd functionality requires two more 
JS files to be included:
-       cometd.js which defines a (constructor) function "org.cometd.Cometd" and
-       jquery.cometd.js (the jQuery binding for cometd) which (among other 
things) invokes that constructor: "new org.cometd.Cometd()".

My JUnitEE test resides in a web application that also has the Java pieces of 
Cometd in its class path. That includes a number of classes and interfaces that 
belong to a package "org.cometd" (and child packages thereof).

Here is what happens when I successively load the JS libraries (using the 
Context.evaluateReader(...)): env-js, cometd.js and jQuery load fine. However, 
when I try to load "jquery.cometd.js", Rhino complains about a name clash (?), 
reporting:

org.mozilla.javascript.EcmaError: TypeError: [JavaPackage org.cometd.Cometd] is 
not a function, it is object. (jquery/jquery.cometd.js#26)
        at 
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3654)
        at 
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3632)
        at 
org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3660)
        at 
org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3679)
        at 
org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3734)
        at 
org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3722)
        at 
org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3363)
        at script(jquery/jquery.cometd.js:26)
        at script(jquery/jquery.cometd.js:4)
        at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2487)
        at 
org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
        at 
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:398)
        at 
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3065)
        at 
org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
        at org.mozilla.javascript.Context.evaluateReader(Context.java:1135)
        at com.sap.gravity.test.client.model.ModelTest.setUp(ModelTest.java:75)
        ...

Seemingly, Rhino is confused about "org.cometd" both being a Java package and a 
JavaScript object. Here is what I tried to get rid of this issue:

(1)     Setting a ClassShutter that rejects all classes belonging to 
"org.cometd" and sub packages --> no change.
(2)     Defining my custom ClassLoader and setting it as the application class 
loader for the Rhino context. That custom ClassLoader (a) throws a 
ClassNotFoundException in findClass(...) for all classes belonging to 
org.cometd and sub packages, (b) does not report "org.cometd" (or any sub 
package thereof) in "getPackages" and (c) returns null for getPackage(...) when 
called with "org.cometd" (or any sub package thereof) --> no change either.

I am starting to run out of ideas apart from removing the org.cometd stuff from 
my class path (which would be somewhat unfortunate as I would also like to 
include some test cases for the Java part). However, I was wondering if there 
are any other chances to work around this issue... Any hint would be greatly 
appreciated.

Thanks and cheers,
Soeren

Mandatory Disclosure Statements: http://www.sap.com/company/legal/impressum.epx

Please be considerate of the environment before printing this email. Thank you!





_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to