rhino

Problems using Rhino on Android

匿名 (未验证) 提交于 2019-12-03 01:25:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to use Mozilla Rhino in my Java application for Android to evaluate some JavaScript. I am using Eclipse + ADT plugin. First I tried simply downloading the Rhino .jar file from Mozilla's website and adding it to the project as a library in Eclipse. Eclipse recognised it fine and compiled the application. However, when running it I get an exception when calling Context.evaluateReader() (see below for stack trace). Then I tried adding the Rhino source code as a separate Android project in Eclipse, marking it as a library and

Rhino Mocks: AAA Synax: Assert property was set with a given type

匿名 (未验证) 提交于 2019-12-03 01:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to assert that a property in a mock object was set with a given type. The property has an abstract type and is set with one of a number of concrete types. This is what I'm trying to do, and it's always passing the test regardless of the value that Foo.DoSomething() sets Foo.Bar with: [ Test ] public void DoSomething_SetsCorrectBar () { // Arrange Foo foo = MockRepository . GenerateMock < Foo >(); // Creates mock in Replay mode (what I want for AAA syntax). // Act foo . DoSomething (); // Assert that DoSomething set Foo

java 脚本引擎Rhino执行js代码和文件

匿名 (未验证) 提交于 2019-12-02 21:52:03
测试js脚本引擎 public class helloworld { public static void main(String[] args) throws Exception { //获得脚本引擎对象 ScriptEngineManager sem=new ScriptEngineManager(); ScriptEngine engine=sem.getEngineByName("javascript"); //定义变量,会存储到引擎上下文种,java和js都能取到 engine.put("msg","good man"); String str="var user= {name:'我',age:18,schools:['高中','大学']};"; str+="print(user.name);"; //执行脚本 engine.eval(str); //js代码修改 engine.eval("msg = 'i am a good man';"); //java获取值 System.out.println(engine.get("msg")); //定义js函数 engine.eval("function add(a,b){var sum=a+b;return sum;}"); //执行js函数 //取得调用接口 Invocable jsInvoke =(Invocable

how to run a javascript function asynchronously, without using setTimeout?

大兔子大兔子 提交于 2019-12-02 19:18:19
its a server side Javascript (rhino engine), so setTimeout is not available. how to run a function asynchronously? Justin Ethier Have a look at the Multithreaded Script Execution example on the Rhino Examples page. Basically, JavaScript does not support threading directly, but you may be able to use a Java thread to achieve what you are looking for. You can use java.util.Timer and java.util.TimerTask to roll your own set/clear Timeout and set/clear Interval functions: var setTimeout, clearTimeout, setInterval, clearInterval; (function () { var timer = new java.util.Timer(); var counter = 1;

What is the difference between Rhino and Spidermonkey JavaScript engines?

孤者浪人 提交于 2019-12-02 18:29:28
For the first time, I began learning Javascript, however on the start I stuck up with two possible options: Rhino and Spidermonkey. Could you please, tell me what is one, and what is another, so I can easily choose for myself the best option that suits my needs. If it makes easier for you, you can list advantages and disadvantages of both Javascript versions. It depends on what you're trying to do with JavaScript. If your intent is just to learn the language then I recommend using a web browser such as Chrome or Firefox and using their built-in (or addon) JavaScript consoles. As to your

rhino vs spidermonkey

空扰寡人 提交于 2019-12-02 15:52:59
I noticed ubuntu 10.04 removed the spidermonkey package. Rhino looks like it's still there though. What are the differences between rhino and spidermonkey (besides what language they're written in). And why did they remove spidermonkey? I'm afraid the difference is the language they are written in, or what it means. People use C/C++ to write all manner of things (like Firefox) whereas Java is most prevalent in Application Servers. From http://en.wikipedia.org/wiki/Rhino_%28JavaScript_engine%29 : Rhino converts JavaScript scripts into Java classes. Rhino works in both compiled as well as

EnvJS/Rhino, setTimeout() not working

我怕爱的太早我们不能终老 提交于 2019-12-02 15:21:55
问题 I currently set up EnvJS on my system (installed from here). My end goal is to load a page let it's javascript process for a few seconds, and then read the dom to get the information of interest. However I can not get setTimeout() to work to save my life (Or JQuery for that matter). I have a php script that starts the process: ... $ENVJS_PATH = "/var/www/project/src/envjs"; $RHINO_JAR = "rhino/js.jar"; $INIT_SCRIPT = "init.js"; $output = shell_exec("java -jar $ENVJS_PATH/$RHINO_JAR -opt -1

How set classpath for Rhino debugger plugin in Eclipse?

巧了我就是萌 提交于 2019-12-02 10:56:57
Actually I am using the Rhino plugin in Eclipse. To use a Java class in JavaScript there is no problem when I just use class which is in RT.JAR. But whenever I want to use my class' "custom classes" then the problem begins due to the classpath. Steps made by me make a class and put it into a JAR file. add it 'jar' into an external JAR file in Eclipse. use it into a JavaScript file and debug it as Rhino debugger in Eclipse. error due to class not defined, "Due to class path is not set properly". The error js: uncaught JavaScript runtime exception: ReferenceError: "Temp" is not defined.

Rhino: return JSON from within Java

余生颓废 提交于 2019-12-02 03:53:08
问题 I have the string representation of a JSON-serialized object in Java e.g. "{\"name\":\"John\",\"age\":24}" . How do I parse and return it to the JavaScript context, just the way JSON.parse(str) would work in JS? Thanks. 回答1: The latest version of Rhino has only four args, and the fourth cannot be null. To solve this, you must create a simple class that implements org.mozilla.javascript.Callable: import org.mozilla.javascript.Callable; import org.mozilla.javascript.Context; import org.mozilla

Rhino: Access Java interface variables in Javascript implementation

亡梦爱人 提交于 2019-12-02 02:21:47
问题 Rhino: How to access Java interface variables in Javascript implementation? I expose a java interface for some other party to let them provide an implementation for the same in javascript. public interface APIInterface{ public static APIUtils util = new APIUtils(); public ArrayList getAllObjects(Object aTransaction); } Javascript implementation: /** Core Interface Method **/ new Object() { getAllObjects: function(tran) { tran.set(..); //OK tran.set(..); //OK util.callSomeFunction(); //Fails