Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery in rhino

I'm trying to load jquery into Rhino as demonstrated by this link here. But I keep getting the following error:

line 1086: uncaught JavaScript runtime exception: TypeError: Cannot call method "importNode" of null

I think it's that jQuery is failing to load altogether - but I have no idea why. I'm using the same index.html file that the author posted in source control.

Here is the trace from my Rhino console:

js> load( "/temp/env.js" );
js> window.location = '/temp/index.html';
/temp/index.html
js> load( "/temp/jquery.js" );
js: "/temp/jquery.js", line 1086: uncaught JavaScript runtime exception: TypeError: Cannot call method "importNode" of null
    at /temp/jquery.js:1086
    at /temp/jquery.js:1079
    at /temp/jquery.js:16
    at <stdin>:41

Any ideas?

like image 896
javamonkey79 Avatar asked Feb 23 '11 09:02

javamonkey79


2 Answers

I was using an OLD version of the env.js file. It turns out the author's really ran with it and moved it over to it's own sites, etc, etc.

The new stuff is here.

As soon as I started using it it was golden with jQuery 1.5.

like image 102
javamonkey79 Avatar answered Nov 03 '22 16:11

javamonkey79


I don't think jQuery (and many other web JS libraries) will work in Rhino because that JavaScript runtime doesn't provide the expected "browser globals" like "document", "navigator", etc. The error message you list indicates that the library is trying to read an attribute (or call a method) of some (presumably browser) object that doesn't exist in the Rhino environment.

The "env.js" project should do exactly this sort of browser environment mockup but it appears to be experimental and might not be compatible with the version of jQuery you're trying to use.

like image 3
maerics Avatar answered Nov 03 '22 16:11

maerics