rhino

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

荒凉一梦 提交于 2019-12-03 06:42:33
问题 its a server side Javascript (rhino engine), so setTimeout is not available. how to run a function asynchronously? 回答1: 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. 回答2: 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

What is the difference between Rhino and Spidermonkey JavaScript engines?

帅比萌擦擦* 提交于 2019-12-03 05:11:41
问题 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. 回答1: 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

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

核能气质少年 提交于 2019-12-03 03:31:02
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 do. There's a short tutorial here: Scripting: Compiling Scripts in Java jbeard4 My solution here: Has

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

强颜欢笑 提交于 2019-12-03 03:16:52
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 with unit tests? What tool did you use and, if it is someone I have mentioned, how did you use it? You

rhino vs spidermonkey

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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? 回答1: 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

Launch jsdom from Rhino on Java

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm following up on this answer : I managed to run simple JavaScript code from Rhino Engine on Java. But when it comes to D3.js , for example: var svg = d3.select("body").append("svg") as you can see d3 requires DOM to be available on first place. So, for that reason JSDOM is supposed to be the solution. But JSDOM happens to be depended on requirejs From RequireJs site: The r.js file allows you to run the optimizer as well as run modules in Node, Rhino or xpcshell. Then my Java Rhino code look like this: FileReader fr1 = new FileReader("lib

rhino vs spidermonkey

给你一囗甜甜゛ 提交于 2019-12-03 02:23:47
问题 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? 回答1: 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

Rhino: How to call JS function from Java

匿名 (未验证) 提交于 2019-12-03 01:55:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using Mozilla Rhino 1.7r2 (not the JDK version), and I want to call a JS function from Java. My JS function is like this: function abc(x,y) { return x+y } How do I do this? Edit: (The JS function is in a separate file) 回答1: String script = "function abc(x,y) {return x+y;}"; Context context = Context.enter(); try { ScriptableObject scope = context.initStandardObjects(); Scriptable that = context.newObject(scope); Function fct = context.compileFunction(scope, script, "script", 1, null); Object result = fct.call( context, scope, that, new

Switching user in Fabric

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a problem when using Fabric to mimic my SSH workflow to deploy my web application. Here's my usual flow of commands when I SSH to a server: SSH using root user. ssh root@1.2.3.4 Switch to web user: su - web Change directory: cd /srv/web/prod/abc_project Start virtualenv: workon abc_env Perform git pull: git pull origin master Run a script: build_stuff -m build Run another script: ./run I tried to write this as a deploy script in Fabric and I get a shell output when su - web is entered. I have to hit Ctrl-D to continue the script. I am

Switching user in Fabric

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a problem when using Fabric to mimic my SSH workflow to deploy my web application. Here's my usual flow of commands when I SSH to a server: SSH using root user. ssh root@1.2.3.4 Switch to web user: su - web Change directory: cd /srv/web/prod/abc_project Start virtualenv: workon abc_env Perform git pull: git pull origin master Run a script: build_stuff -m build Run another script: ./run I tried to write this as a deploy script in Fabric and I get a shell output when su - web is entered. I have to hit Ctrl-D to continue the script. I am