rhino

How can I specify my own Rhino context in Java?

﹥>﹥吖頭↗ 提交于 2019-12-02 01:01:29
I'm trying to ensure that my Rhino scripts (running under Java 6) are strict so that if a script developer misspells an expression I want an exception to be thrown. Currently what happens is the expression simply evaluates to "undefined". Now according to Mozilla org https://developer.mozilla.org/en/New_in_Rhino_1.6R6 there are features to enable strict checking in the context. I cannot find a working example of this. What I did so far was write a class to extend ContextFactory and then override the hasFeature method. public class ScriptContextFactory extends ContextFactory { protected boolean

Rhino: return JSON from within Java

那年仲夏 提交于 2019-12-02 00:57:43
I have the string representation of a JSON-serialized object in Java e.g. "{\"name\":\"John\",\"age\":24}" . How do I parse and return it to the JavaScript context, just the way JSON.parse(str) would work in JS? Thanks. The latest version of Rhino has only four args, and the fourth cannot be null. To solve this, you must create a simple class that implements org.mozilla.javascript.Callable: import org.mozilla.javascript.Callable; import org.mozilla.javascript.Context; import org.mozilla.javascript.Scriptable; public class NullCallable implements Callable { @Override public Object call(Context

How do I build the Rhino specific versions of less?

旧街凉风 提交于 2019-12-01 23:42:51
问题 I want to run the latest version of less from Java, for this (I believe) I need the Rhino specific versions of less. From the less website: Each less.js release contains also rhino-compatible version. But this appears to have been not the case since v1.7.5. So I've installed NPM, installed Grunt, downloaded the less source from GitHub, ran grunt -help to find the rhino task but have fallen at the last hurdle: C:\Temp\less.js-2.5.0> grunt rhino Running "browserify:rhino" (browserify) task

Rhino: Access Java interface variables in Javascript implementation

柔情痞子 提交于 2019-12-01 23:18:42
Rhino: How to access Java interface variables in Javascript implementation? I expose a java interface for some other party to let them provide an implementation for the same in javascript. public interface APIInterface{ public static APIUtils util = new APIUtils(); public ArrayList getAllObjects(Object aTransaction); } Javascript implementation: /** Core Interface Method **/ new Object() { getAllObjects: function(tran) { tran.set(..); //OK tran.set(..); //OK util.callSomeFunction(); //Fails here..Rhino doesn't understand util.. } } I want the javascript implementation of the interface to

How do I build the Rhino specific versions of less?

陌路散爱 提交于 2019-12-01 22:39:11
I want to run the latest version of less from Java, for this (I believe) I need the Rhino specific versions of less. From the less website : Each less.js release contains also rhino-compatible version. But this appears to have been not the case since v1.7.5 . So I've installed NPM, installed Grunt, downloaded the less source from GitHub, ran grunt -help to find the rhino task but have fallen at the last hurdle: C:\Temp\less.js-2.5.0> grunt rhino Running "browserify:rhino" (browserify) task Verifying property browserify.rhino exists in config...ERROR >> Unable to process task. Warning: Required

Using Rhino instead of ScriptEngine to run Javascript code in Java

拈花ヽ惹草 提交于 2019-12-01 15:39:38
Based on the discussion converting string representation of unknown date-format to Date in java , I want to use the JavaScript Date function in my App-Engine project. However, ScriptEngine does not work on App-Engine. So I need a little help converting to Rhino. Here is the ScriptEngine code I need to convert: ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine engine = scriptEngineManager.getEngineByName("JavaScript"); String script = "var date = new Date('" + dateInUnknownFormat + "'); var timestamp = date.getTime();"; engine.eval(script); long timestamp = (

Rhino Javascript: How to convert Object to a Javascript primitive?

我是研究僧i 提交于 2019-12-01 11:26:09
I am utilizing the javax.scripting with Rhino in this project. I have a Java method that returns a Java Object (Double, Long, Integer, etc). I want to call that method from javascript and reference the result as a Javascript primitive type. However, javacript recognizes the return type as an Object. How do I force it to convert to a javascript primitive? This question is very similar to http://groups.google.com/group/mozilla.dev.tech.js-engine.rhino/browse_thread/thread/2f3d43bb49d5288a/dde79e1aa72e1301 The problem with that is how do I get a reference to the context and the WrapFactory?

Including a JavaScript file during Rhino eval

对着背影说爱祢 提交于 2019-12-01 09:33:27
How would one include a script "Bar" from within another script "Foo" that is being evaluated by the Rhino Engine, running in Java. IE, setup the script engine like this in Java: ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("javascript"); BufferedReader br = new BufferedReader(new FileReader(new File("Foo.js"))); engine.eval(br); ... and put the following in Foo: load(["Bar.js"]) According to Rhino shell documentation , that's the way to do it. But when running from Java, it's clearly not implemented: javax.script.ScriptException: sun

Rhino Javascript: How to convert Object to a Javascript primitive?

和自甴很熟 提交于 2019-12-01 08:59:09
问题 I am utilizing the javax.scripting with Rhino in this project. I have a Java method that returns a Java Object (Double, Long, Integer, etc). I want to call that method from javascript and reference the result as a Javascript primitive type. However, javacript recognizes the return type as an Object. How do I force it to convert to a javascript primitive? This question is very similar to http://groups.google.com/group/mozilla.dev.tech.js-engine.rhino/browse_thread/thread/2f3d43bb49d5288a

Including a JavaScript file during Rhino eval

浪尽此生 提交于 2019-12-01 07:06:28
问题 How would one include a script "Bar" from within another script "Foo" that is being evaluated by the Rhino Engine, running in Java. IE, setup the script engine like this in Java: ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("javascript"); BufferedReader br = new BufferedReader(new FileReader(new File("Foo.js"))); engine.eval(br); ... and put the following in Foo: load(["Bar.js"]) According to Rhino shell documentation, that's the way