rhino

How Mozilla Rhino can use nodejs “fs” module?

孤街醉人 提交于 2019-12-11 09:04:32
问题 Let's say I have my.js file that has dependency on nodejs fs module. Like: var fs = require('fs'); The question: How can I load Core NodeJS module like "FS" in My Mozilla Rhino Java Code to be able to run my.js that depends on it ? 回答1: I don't think you can do this. fs module just a wrapper for native bindings built into node.js itself. There are some thoughts flying in the sky of node.js community about being able to use different JS engines inside node.js but I don't think we will see this

Build a JS server inside of Java for Google AppEngine

坚强是说给别人听的谎言 提交于 2019-12-11 08:48:14
问题 I just needed to create a little interface for a project. So I decided to take given code and to run it on Google AppEngine. My problem is, that I'm experienced in JavaScript and got some basic knowledge of Java, but I got no clue how a Java webapp has to be structured. I started Eclipse and installed the AppEngine-addon, downloaded Rhino and env.js (which is necessary for the bunch of code I need to run) but then found me in the situation of sitting on this files not knowing where to put

How to set Expect to a Extension method in Rhino Mocks 3.6

Deadly 提交于 2019-12-11 08:15:56
问题 Good afternoon I have a class and it has an associated extension method. public class Person{ public int ID {get;set} public string Name {get;set} } Extension method: public static class Helper { public static int GetToken(this Person person){ int id = 0; //Something here is done to read token from another service... return id; } } Now I am trying to use Rhino and test this method public void readPersonToken(int personId) { var person = Person.GetPersonInfo(personId);//we consume a service

How to subclass an inner (static) class in Rhino?

你说的曾经没有我的故事 提交于 2019-12-11 05:55:16
问题 I'm trying to subclass an inner class (defined in Java) in Rhino, and I can't seem to make it work. I've got some compiled Java code (which I essentially can't change) that has an inner abstract class: package mypackage; class MyClass { abstract static class MyInnerClass { abstract void print(String s); } } From Rhino, I can see it just fine: js> Packages.mypackage.MyClass.MyInnerClass [JavaClass mypackage.MyClass$MyInnerClass] But I can't figure out how to subclass it. I figured something

Using a config file for JSHint with Rhino

不想你离开。 提交于 2019-12-10 18:25:22
问题 I'm attempting to run jsHint from the command line using Rhino. I want to make the check an automatic part of my teams checkin process. I have the basic configuration working using the command: java -jar .rhino.jar ./jshint.js ./samplefile.js That outputs the standard jsHint messages for my (intentionally error-ridden) sample file. And adding config comments to the top of the sample file works correctly. However I would like to add a project level config file to specify the options I want for

sun.org.mozilla.javascript.internal.NativeObject vs org.mozilla.javascript.NativeObject

杀马特。学长 韩版系。学妹 提交于 2019-12-10 11:19:22
问题 I am really stuck at this now.. Essentially I have a Java Map, which I would like to pass it to a Javascript Code, so that in my JS code I can use dot notation to refer the keys in this Map. ( I know I can serialize the map into JSON and deserialize it back and pass it into JS, but I don't like that ) I have this piece of the unit code @Test public void mapToJsTest() throws Exception{ Map m = Maps.newHashMap(); m.put("name", "john"); NativeObject nobj = new NativeObject(); for (Object k : m

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

Deadly 提交于 2019-12-10 10:15:11
问题 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.) 回答1: require is a CommonJS

Java 脚本引擎入门

天大地大妈咪最大 提交于 2019-12-10 05:04:43
Java Script Engine Java 脚本引擎可以将脚本嵌入Java代码中,可以自定义和扩展Java应用程序,自JDK1.6被引入,基于Rhino引擎,JDK1.8后使用Nashorn引擎,支持ECMAScript 5,但后期还可能会换。 脚本引擎包位于javax.script中,各个类名及描述如下 接口 Bindings 键值对映射,所有key都为String Compilable 由具体的脚本引擎实现,用于将脚本进行编译,可重复使用。 Invocable 由具体的脚本引擎实现,其允许调用先前已执行的脚本 ScriptContext 脚本引擎上下文,用于将应用程序与脚本引擎进行绑定 ScriptEngine 由具体的脚本引擎实现,定义了执行脚本的方法、键值对映射关系、脚本引擎上下文 ScriptEngineFactory 脚本引擎工厂,每一个ScriptEngine都有一个对应的工厂。ScriptEngineManager会从ClassLoader中获取所有的ScriptEngineFactories实例 类 AbstractScriptEngine ScriptEngine的抽象实现类,提供了ScriptEngine的标准实现 CompiledScript 由存储编译结果的类扩展。可以以Java类、Java类文件或者脚本操作码的形式存储,可以重复执行无需重新解析

Rhino load() function available in JavaScript provided by javax.script?

六月ゝ 毕业季﹏ 提交于 2019-12-10 04:09:58
问题 Some JavaScript files that have been developed for Rhino's shell use load() to load additional JavaScript files. I'm attempting to embed functionality from one of these Rhino JavaScript files using javax.script. Unfortunately, the load() function is not implemented by javax.script's JavaScript. When attempting to eval() a script containing load(), the following error occurs: com.sun.script.javascript.RhinoScriptEngine:-1:in `eval': javax.script.ScriptException: sun.org.mozilla.javascript

How to use Maven classpath to run Java main class?

混江龙づ霸主 提交于 2019-12-10 03:59:57
问题 I'm currently using Maven to build my Rhino JavaScript project, download dependent libraries, and manage the classpath at runtime. I'm able to run the JavaScript entry point by using the Maven exec plugin, in the following way: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.1</version> <executions> <execution> <goals> <goal>java</goal> </goals> </execution> </executions> <configuration> <mainClass>org.mozilla.javascript.tools.shell.Main<