rhino

Rhino: restrict Java packages that can be accessed from JavaScript

孤街醉人 提交于 2019-12-03 17:52:16
问题 When embedding a JavaScript interpreter (Rhino) into a Java application (to be able to script that application), how would one go about restricting the Java packages that are available to scripts? For example, only "java.lang.*" should be accessible. 回答1: A method for blocking access to certain packages and classes (including through reflection) in Rhino is described here. The important interface is ClassShutter which provides access control for Rhino's LiveConnect support. 回答2: how about

example using rhino's JavaAdapter

空扰寡人 提交于 2019-12-03 16:14:05
Can someone provide me an example on how to extend a java class in java script using Rhino's java adapter ? For anyone else who might come across this, there's a decent example here (the author uses it to extend awt.Canvas ). var smileyCanvas = new JavaAdapter(awt.Canvas, { paint: function (g) { var size = this.getSize(); var d = Math.min(size.width, size.height); var ed = d / 20; var x = (size.width - d) / 2; var y = (size.height - d) / 2; // draw head (color already set to foreground) g.fillOval(x, y, d, d); g.setColor(awt.Color.black); g.drawOval(x, y, d, d); // draw eyes g.fillOval(x+d/3-

How can I add an object property to the global object in rhino javascript

╄→尐↘猪︶ㄣ 提交于 2019-12-03 14:37:52
I have some properties in an object that I would like to add to the global namespace. In javascript on the browser I could just add it to the window object like so: var myObject = { foo : function() { alert("hi"); } // and many more properties }; for (property in myObject) { window[property] = myObject[property]; } // now I can just call foo() foo(); But since rhino doesn't have the global window object I can't do that. Is there an equivalent object or some other way to accomplish this? You could use this , which refers to the global object if the current function is not called as a method of

Debug Javascript within Eclipse using Rhino

纵饮孤独 提交于 2019-12-03 13:58:56
问题 I have installed JavaScript Development Tools Plugin for Eclipse, but i am not able to run or debug a JavaScript Project. I want to debug using the inbuilt Rhino Interpreter, not using a web browser. I have created a JavaScript project and when I try to create a run configuration, it says "Please select a valid project" and the run button is greyed out.. Please view the attached snapshot. 回答1: Which version of eclipse are you using? Install Eclipse 3.7 Java EE Version, there you could

How to compile rhino/javascript files to .class bytecode for java at runtime

给你一囗甜甜゛ 提交于 2019-12-03 13:31:36
问题 I'm making a falling sand game in Java. I want users to be able to write their own engine for it using a simpler language. Falling sand games can be very CPU intensive so I want to have the engine running as fast as possible while not having to manually compile. I need to know how to compile rhino javascript files to .class files by at runtime to be used. I've looked for a way but couldn't find any other than manually compiling it by using the command line which I don't want users to have to

Running unit tests of JavaScript code from XUL - what and how

可紊 提交于 2019-12-03 12:57:40
问题 I am writing an XUL application. It is not a Firefox extension but a standalone app to be used through XULrunner. My intention is to adopt TDD in my development process and I am looking at RhinoUnit as my unit testing framework. I will try to use it anyway but there is not much documentation about testing XUL applications. Some people talk about using UxU - but only for Firefox addons - and Mochitest - if you want to test Mozilla only. My question is: has someone written some XUL application

Is it possible to make Node.js use Rhino as the Javascript engine?

允我心安 提交于 2019-12-03 11:25:53
I use Node.js for several jobs on my web apps and so far everthing's ok. But the Node.js uses Google's V8 as the default Javascript engine (JSE) and V8 runs exlusively on the x86 and ARM Instruction Set Architectures (ISA). Now I have a PPC processor Mac computer on which I want to run the Node.js . To do that, I'm adviced to use the Rhino + OpenJDK Shark Virtual Machine + Low Level Virtual Machine ( LLVM ) as the JIT compiler. Currently, that looks like the most applicable way of running Node.js on the PPC ISA. Or, is there a better way to do it? Could you tell beforehand if it would be

building java script debugger for rhino [closed]

我只是一个虾纸丫 提交于 2019-12-03 09:45:45
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . i am using tomcat server and i have added a rhino engine to able some scripting abilities on my users. the second phase is to provide some debug environment. i know rhino has a debug API but i could not find any documentation/code samples about how to work with it, and build a debugger around it any one knows?

Are there any tips & tricks for making rhino perform faster? [closed]

坚强是说给别人听的谎言 提交于 2019-12-03 07:24:35
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Are there any tips & tricks for making rhino perform faster? I'm trying to compress a large js file using uglifyJs in Rhino and it takes more than a minute. Do you have any hints or other alternatives for rhino in java server side space? With the JavaScript

android Rhino error can't load this type of class file

依然范特西╮ 提交于 2019-12-03 07:10:31
I'm using Rhino in android to execute JavaScript function code in Android(java) and get the result from this code, but I got this exception 01-22 11:33:57.063: E/AndroidRuntime(29175): Caused by: java.lang.UnsupportedOperationException: can't load this type of class file This is my code String test = "function abc(x,y) {return x+y;}"; org.mozilla.javascript.Context context = org.mozilla.javascript.Context.enter(); try { ScriptableObject scope = context.initStandardObjects(); Scriptable that = context.newObject(scope); Function fct = context.compileFunction(scope, test, "script", 1, null);