rhino

Access variable of ScriptContext using Nashorn JavaScript Engine (Java 8)

谁说胖子不能爱 提交于 2019-12-13 13:49:51
问题 I used the following code with the Rhino JavaScript engine in Java: @Test public void testRhino() throws ScriptException { final ScriptEngineManager factory = new ScriptEngineManager(); final ScriptEngine engine = factory.getEngineByName("rhino"); final String raw = "I am the raw value injected"; final ScriptContext ctx = new SimpleScriptContext(); ctx.setAttribute("raw", raw, ScriptContext.ENGINE_SCOPE); String script = "var result = 'I am a result';"; script += "java.lang.System.out.println

How do I hide a class method from Rhino Script Engine?

别等时光非礼了梦想. 提交于 2019-12-13 04:33:43
问题 If I pass an object to Rhino in Java, is there an annotation I can use in that object's class to hide methods\fields from Rhino JavaScripts to make them inaccessible to the JavaScripts? Or any other method of doing this? I did some research, and it looks like I could wrap the Objects with Scriptable, but that seems like a messier solution than what might be potentially really easy to do as it seems like it would be a fairly standard feature. Thanks. 回答1: I wasn't able to find any support for

Java 6 ScriptEngine and JSON.parse problem

隐身守侯 提交于 2019-12-12 19:12:27
问题 The Rhino release that is included in Java 6 ScriptEngine does not have a JSON parser. I've tried including crockfords JSON2.js in my script on the scriptengine.eval() . When I try to do the JSON.parse , it ends up giving me a script error that .replace is an unknown function. .replace is referenced several places in JSON2, and it works fine inside a browser (IE7, IE8, FF3). Anyone see this and have a suggestion? 回答1: Thanks for loooking at this. I solved it. Pilot Error. Simply put, the

Custom settings with jshint-rhino.js

心不动则不痛 提交于 2019-12-12 19:02:08
问题 I've been using jshint with node but just recently had to switch over to using it with Rhino. I used to be able to do: jshint --config=jsHintConfig.json fileToLint.js Now, I've tried replacing that call with: rhino jshint-rhino.js --config=jsHintConfig.json fileToLint.js But it doesn't seem to work. I only get the following printed to the console: Usage: jshint.js file.js Does jshint-rhino not accept a json configuration file? Update: http://anton.kovalyov.net/2011/03/01/jshint-edition-update

How to configure rhino to run jasmine tests for angularjs controllers

ぐ巨炮叔叔 提交于 2019-12-12 16:18:29
问题 I am having trouble getting unit tests working for an Angular JS app using Jasmine sbt plugin. when I add angular.js ( ver 1.3.1) to test.dependecies.js EnvJasmine.loadGlobal(EnvJasmine.libDir + "/angular.js"); EnvJasmine.loadGlobal(EnvJasmine.libDir + "/ui-bootstrap-0.11.2.js"); EnvJasmine.loadGlobal(EnvJasmine.testDir + "/lib/angular-mocks.js"); I got the following error [ Envjs/1.6 (Rhino; U; Linux amd64 3.13.0-32-generic; en-US; rv:1.7.0.rc2) Resig/20070309 PilotFish/1.2.13 ] Could not

Getting function names and their arguments from evaluated JS with Rhino

可紊 提交于 2019-12-12 13:28:22
问题 I'm using Rhino. and after doing Context cx = Context.enter(); Scriptable scope = cx.initStandardObjects(); cx.evaluateString(scope, "function f(x,y){ return x+y}", "<cmd>", 1, null); I'd like to know that there's a function with the name f and two parameters x and y but could not find any methods that can help me with that. 回答1: Try to use next code. package com.qarea.rhinotest; import org.mozilla.javascript.Context; import org.mozilla.javascript.Scriptable; public class RhinoTest { public

Get Rhino JS to see Java class

孤街醉人 提交于 2019-12-12 09:44:55
问题 I'm playing with Rhino, and I've had success using Java classes from the stdlib, but not from Java code I compiled here. For example, this works fine: print(new java.util.Date()); But with NanoHTTPD (single .java file, no namespace, same folder), I'm having no luck at all: js> new Packages.NanoHTTPD() js: "<stdin>", line 4: uncaught JavaScript runtime exception: TypeError: [JavaPackage NanoHTTPD] is not a function, it is object. at <stdin>:4 I'm sure it's something simple. What am I missing?

Rhino for Android

半腔热情 提交于 2019-12-12 02:59:39
问题 I am trying to use rhino in my android project following this. I dawnloaded Rhino and added js.jar in lib . Here is my MainActivity : public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { ... Context rhino = Context.enter(); // try{ // I commented it to catch the error rhino.setLanguageVersion(Context.VERSION_1_2); Scriptable scope = rhino.initStandardObjects(); Object result=rhino.evaluateString(scope, "obj={a:1,b:['x','y']}",

Execute compiled ClojureScript from the commandline with Rhino

你离开我真会死。 提交于 2019-12-12 02:46:10
问题 I understand ClojureScript can be executed within a JavaScript REPL or it can be compiled into JavaScript, then run in a browser. I couldn't find a way to use it on the server side with Rhino. Here is my way of thinking, I have a simple source file: (ns simple.hello) (println "Hello, world") I compile it to hello.js . I try to run java -jar js.jar out/goog/base.js out/goog/deps.js out/hello.js Nothing happens. How can I make it work, or is only Node.js supported on the command line? 回答1: This

Can I build a Rhino JavaAdapter in Java, using a ScriptableObject?

这一生的挚爱 提交于 2019-12-11 09:35:29
问题 I've found a few questions about shuffling class definitions between Javascript and Java using Mozilla's Rhino. I've gotten far enough that this works: Javascript: new JavaAdapter(MyClass, {foo: function(){return 'Hello!';}}); Java String script = // the above stuff Object o = context.evaluateString(scope, script, "UserScript", 1, null); MyClass mc = (MyClass) Context.jsToJava(o, MyClass.class); mc.foo(); // returns "Hello!" That blew me away, but I'd like to move the JavaAdapter construction