2

I am having problems evaluating a script.js file which is dependent of prototype.js. When i am trying to evaluate the script.js file through rhino script engine in java i got Script Exception like "TypeError: $H is not a function, it is java.lang.String.". How do I evaluate the files and how to include prototype.js and to define the prototype objects?

3 Answers 3

2

You cannot evaluate prototype.js using Rhino only. prototype.js have many references to the HTML DOM which is not implemented in Rhino/Java. For example (from prototype.js): document.createTextNode('') The document global object is not defined in Rhino context and createTextNode is not defined too.

The solution is to remove all Objects/Functions from your copy of prototype.js that references the document, window or navigator objects. (assuming your js file does not use them)

Sign up to request clarification or add additional context in comments.

1 Comment

You could also get away with declaring some dummy objects for document, window, navigator and so on. This way you do not have to change prototype.js.
0

have you evaluated them in the correct order? They need to be evaluated from the bottom up

Comments

0

Take a look at env-js, which is a mock browser environment for Rhino. It's based on some work by John Resig to get JQuery working in Rhino. I wouldn't be surprised if Prototype worked as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.