rhino

How to load .js files into a Rhino context in Java

佐手、 提交于 2019-11-29 14:31:11
问题 Here is my situation: I have access to a Rhino Context object in a Java class. I want to read in a bunch of .js files and pass them along to the Rhino context to have them evaluated. I'm not really interested in having the functions in the .js files available in the scripting context so much as I am in just having the variables that are declared in the .js files available (this is a tooling validation kind of issue). Ideally I would read in and try to evaluate each file all at once, not line

How do I call a method of a Java instance from JavaScript?

怎甘沉沦 提交于 2019-11-29 14:22:15
问题 I'm using the Mozilla Rhino JavaScript emulator. It allows me to add Java methods to a context and then call them as if they were JavaScript functions. But I can't get it to work except when I use a static method. The problem is this part of the documentation: If the method is not static, the Java 'this' value will correspond to the JavaScript 'this' value. Any attempt to call the function with a 'this' value that is not of the right Java type will result in an error. Apparently, my Java

Simulating duck typing in Java

[亡魂溺海] 提交于 2019-11-29 12:48:12
问题 The problem: I'd like to be able to generically access in Java any property/field on a Java ojbect similarly to how a dynamic language (think Groovy, JavaScript) would. I won't know at the time I'm writing this plumbing code what type of object it is or what the property/field name will be. But I will know the property/field name when I go to use it. My current solution: So far I've written a simple wrapper class that uses java.beans.Introspector to grab the properties of a Bean/POJO and

Warning: node.js detection failed, sbt will use the Rhino based Trireme JavaScript engine

戏子无情 提交于 2019-11-29 11:18:54
问题 I'm new to Play framework. Please explain the meaning of the below warning. Warning: node.js detection failed, sbt will use the Rhino based Trireme JavaScript engine instead to run JavaScript assets compilation, which in some cases may be orders of magnitude slower than using node.js I don't want anything that slow down my application so please advice if I should change the JS Engine to Node.js, but my PlayFramework project is using Java on the server side. 回答1: You need to install Node.js

Can Nashorn startup slowness be overcome?

核能气质少年 提交于 2019-11-29 06:32:23
I've used Rhino for a scripting component inside graphics. In the project there are about 200 small scripts running independantly. Immediately when starting the application the scripts should be at full speed. Rhino's performance was sufficient, but since Oracle advices to migrate to Nashorn, i'm facing a dilema. Below a picture showing the load difference between Rhino and Nashorn at approximayely 15,000 invocations of the scripts. The Startup slowness of Nashorn is my biggest issue. Note, this was back on JDK 1.8.0. JDK 1.8u5 is similar I hope the picture is clear. This is an outline of how

How can I start coding with Oracle's Nashorn JS Engine and when will it replace Rhino in the OpenJDK?

拟墨画扇 提交于 2019-11-29 05:56:10
问题 I'm looking for a way to start playing around with Oracle's new Nashorn JavaScript Engine. I've DL'd the latest OpenJDK 8 (b65) and it appears that Rhino is still the only included script engine. Anyone know when (or in which build) Nashorn will replace Rhino in the OpenJDK? Or even better, where I can get a JDK with it included already? I know Netbeans has already written a debugger to use it, just not sure where they got the libraries/code to start writing it. Anyone have some links? Thanks

Resolving modules using require.js and Java/Rhino

本秂侑毒 提交于 2019-11-29 04:44:03
问题 I'm trying to get require.js to load modules on the server-side with Java 6 and Rhino. I'm able to load require.js itself just fine. Rhino can see the require() function. I can tell because Rhino complains that it can't find the function when I change require() to something else like requireffdkj() . But when I try to require even a simple JS, like hello.js var hello = 'hello'; using either of the following: require('hello'); require('./hello'); it doesn't work. I get Caused by: javax.script

Access Rhino's native JSON.Stringify from Java

南楼画角 提交于 2019-11-29 04:32:33
Is there a cleaner way to get the JSON representation of a Javascript object than with the following kludge? System.out.println(((ScriptableObject) scope).callMethod( cx, (Scriptable) scope.get("JSON", scope), "stringify", new Object[]{jsObject})); Where jsObject is the ScriptableObject I want to stringify. Note that Hannes has now addressed this in Rhino. So the usage simplifies to this: import org.mozilla.javascript.NativeJSON; // ... Object json = NativeJSON.stringify(cx, scope, jsObject, null, null); The org.mozilla.javascript.NativeJSON class should be public in the Rhino 1.7R4 release. I

Performance of the compiled vs. interpreted javascript in java7 / Rhino

柔情痞子 提交于 2019-11-29 03:01:52
问题 I have a problem with performance of Rhino javascript engine in Java7, shortly - my script (that parses and compiles texts) runs in Chrome around 50-100 times quicker than the same in Java7 Rhino script engine. I was trying to find the way to improve situation and have found that Rhino supports compilation of scripts. I tried doing it with my scripts and actually did not see any improvement. Finally - i ended up with a dummy short test suite where i do not see any difference in performance

What is the lifecycle and concurrency semantics of Rhino Script Engine

℡╲_俬逩灬. 提交于 2019-11-28 18:38:44
I am interested in the lifecycle and concurrency semantics of (Rhino) Script Engine and associated classes. Specifically: Is Bindings supposed to be thread safe? Should multiple threads be allowed to share a single ScriptEngine instance? ... or should each thread construct a short-lived instance? ... or keep them in a pool? What happens if multiple threads concurrently call ScriptEngine.eval(...) ? Same questions for CompiledScript instances Same questions for interface implementations generated using Invocable.getInterface(...) ? Presumably, objects placed in Bindings follow Java's garbage