rhino

using recent Rhino in ant script

元气小坏坏 提交于 2019-12-06 01:49:39
I'm trying to use a recent version of Rhino in an ant tag, but it seems to be using the version of Rhino that comes bundled with the JVM instead. I've tried adjusting the classpath to specify the Rhino script jar. Currently, I've tried the following: <project default="hello" name="hello-world" basedir="."> <target name="hello"> <script language="javascript"> <classpath> <pathelement location="js.jar"/> </classpath><![CDATA[ x=<hello><world/></hello> ]]></script> </target> </project> Notice the inclusion of E4X syntax in the script, which should work only work in Rhino from Mozilla, and not the

Sanity check: Rhino does not have a require function, right?

泄露秘密 提交于 2019-12-06 00:24:54
I'm using rhino from the JVM with the jaxax.script interfaces. I'm trying to evaluate JavaScript that contains 'require' calls. This does not work because there is no definition of 'require'. Is require just a v8 thing? Or maybe just a node.js thing? Are there ways around this on the JVM? Options I can think of are rewrite the js files by manually including the required code call out to a separate node.js process (I'm not necessarily recommending the approaches.) require is a CommonJS spec that node.js (and other frameworks, like RingoJS ) use. The newest version of Rhino does support require

JavaScript window object element properties

梦想的初衷 提交于 2019-12-05 21:38:49
A coworker showed me the following code and asked me why it worked. <span id="myspan">Do you like my hat?</span> <script type="text/javascript"> var spanElement = document.getElementById("myspan"); alert("Here I am! " + spanElement.innerHTML + "\n" + myspan.innerHTML); </script> I explained that a property is attached to the window object with the name of the element's id when the browser parses the document which then contains a reference to the appropriate dom node. It's sort of as if window.myspan = document.getElementById("myspan") is called behind the scenes as the page is being rendered.

How can I pass a javaScript function to a Java Method to act as a callback (Rhino)

ε祈祈猫儿з 提交于 2019-12-05 21:32:44
问题 Basically I'm trying to pass a javaScript function to a Java method to act as a callback to the script. I can do it - sort of - but the object I receive is a sun.org.mozilla.javascript.internal.InterpretedFunction and I don't see a way to invoke it. Any ideas? Here's what I have so far: var someNumber = 0; function start() { // log is just an log4j instance added to the Bindings log.info("started...."); someNumber = 20; // Test is a unit test object with this method on it (taking Object as a

Decent JavaScript IDE [closed]

送分小仙女□ 提交于 2019-12-05 18:15:56
问题 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. Closed 8 years ago . What is a decent IDE for developing JavaScript, I'll be writing both client side stuff and writing for Rhino. Ideally It needs to run

Get variables from javascript expression (Rhino)

不打扰是莪最后的温柔 提交于 2019-12-05 17:58:11
I'm using Rhino to evaluate js expressions, by putting all the possible variable values in the scope and evaluating an anonymous function. However the expressions are fairly simple and I would like to put only the values used in the expression, for performance. Code sample: Context cx = Context.enter(); Scriptable scope = cx.initStandardObjects(null); // Build javascript anonymous function String script = "(function () {" ; for (String key : values.keySet()) { ScriptableObject.putProperty(scope, key, values.get(key)); } script += "return " + expression + ";})();"; Object result = cx

Get Rhino JS to see Java class

≡放荡痞女 提交于 2019-12-05 15:54:14
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? EDIT : I'm launching it like this: $ CLASSPATH=. java -jar rhino.jar or this: $ java -classpath . -jar

How to append xml nodes (as a string) into an existing XML Element node (only using java builtins)?

感情迁移 提交于 2019-12-05 14:51:02
(Disclaimer: using Rhino inside RingoJS) Let's say I have a document with an element , I don't see how I can append nodes as string to this element. In order to parse the string to xml nodes and then append them to the node, I tried to use documentFragment but I couldn't get anywhere. In short, I need something as easy as .NET's .innerXML but it's not in the java api. var dbFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance(); var dBuilder = dbFactory.newDocumentBuilder(); var doc = dBuilder.newDocument(); var el = doc.createElement('test'); var nodesToAppend = '<foo bar="1">Hi

Rhino: How to get all properties from ScriptableObject?

*爱你&永不变心* 提交于 2019-12-05 10:54:22
I am using a Javascript object as an object with configuration properties. E.g. I have this object in javascript: var myProps = {prop1: 'prop1', prop2: 'prop2', 'prop3': 'prop3'}; This object (NativeObject) is returned to me in Java function. E.g. public Static void jsStaticFunction_test(NativeObject obj) { //work with object here } I want to get all properties from object and build HashMap from it. Any help will be appreciated. well, if you looked closer, you would have seen that NativeObject implements the Map interface, so you could have worked very well with the NativeObject.... But to

Rhino and concurrent access to javax.script.ScriptEngine

↘锁芯ラ 提交于 2019-12-05 10:46:07
问题 I'm using Rhino 1.6r2 through the javax.script API. I know that the Rhino engine claims to be MULTITHREADED: "The engine implementation is internally thread-safe and scripts may execute concurrently although effects of script execution on one thread may be visible to scripts on other threads." What I'd like to know is, under what exact conditions would the effects of one script execution be visible to another? In my code, I sometimes re-use a ScriptEngine object, but for every execution I