Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create a 'window' object for javascript running in the Java6 Rhino Script Engine

  • I want to run some Javascript on my Java6 server - i.e. using the javax.script API, specifically the Rhino Script Engine. (Although another solution would be acceptable)
  • The script file is created & supported by a third party, so I don't want to download it and edit it in case it changes over time.
  • The script directly references the 'window' object ( and probably the 'document' object etc. ) which Rhino does not seem to support.

Can I do this, and if so, how?

like image 307
barryred Avatar asked Jun 08 '09 11:06

barryred


People also ask

What is substitute of Rhino JavaScript engine in Java 8?

Until Java SE 7, JDKs shipped with a JavaScript scripting engine based on Mozilla Rhino. Java SE 8 will instead ship with a new engine called Oracle Nashorn, which is based on JSR 292 and invokedynamic .

Does Rhino support ES6?

As of version 1.7R11 (May 2019), Rhino supports Java 8 and up, and supports a number of ECMAScript ES6/ES2015 features.


1 Answers

var window = {}
var document = {}

... of course, they won't do a lot of good unless you populate them with the properties that the script is trying to access.

You can't just populate them with the standard browser APIs - most of them don't make sense outside the context of the browser.

like image 127
Quentin Avatar answered Sep 30 '22 01:09

Quentin