nashorn

ECMA 6 support in Nashorn

。_饼干妹妹 提交于 2019-12-23 18:31:19
问题 I just tried out Nashorn and it seems not to support Array.prototype.fill . Is this surprising? Is there a timeline somewhere for Nashorn's intended support? Is the best way to get an array of say 5 0s in Nashorn currently Array.apply(null, Array(5)).map(x=>0) ? 回答1: Seems there is partial support for ES6 in Java9 and more coming later: https://www.oracle.com/corporate/features/nashorn-javascript-engine-jdk9.html Also see: http://openjdk.java.net/jeps/292 回答2: This documentation would have me

Using Nashorn in Java?

十年热恋 提交于 2019-12-23 15:23:16
问题 I'm reading about new Java 8 features and came to know it comes with Nashorn (Javascript engine). Can someone explain me why would/should I use a Javascript engine inside Java. What programming problems it would solve ? any examples Thanks, Ravi 回答1: Simply, it would allow you to create standalone JavaScript programs and allow embedding JavaScript in Java. Java must be compiled into what is known as a "machine language" before it can be run. JavaScript is text-based and interpreted, and is

Is it worked Nashorn JS object to java.util.Map?

天涯浪子 提交于 2019-12-23 09:34:41
问题 I have java method void someMethod(String str, Map map) { ... } From JS call this method var map = new Object() map.key1 = "val1" ...someMethod(str, map) Exception: java.lang.NoSuchMethodException: None of the fixed arity signatures [(java.lang.String, java.util.Map)] of method org.prjctor.shell.Bash.eval match the argument types [java.lang.String, jdk.nashorn.internal.scripts.JO] But in Nashorn docs "Mapping of Data Types Between Java and JavaScript" said "Every JavaScript object is also a

Casting Array Result From JavaScript to Something Useful Using ScriptObjectMirror

筅森魡賤 提交于 2019-12-22 17:59:13
问题 If I have a JS function that returns an array of strings, how should I go about casting it to a useful type (I'm thinking either a Java array or Collection class)? I've noticed that the return type is always a ScriptObjectMirror which has an interesting to(Class<?> clazz) method, but I'm uncertain on it's use. I've checked several other StackOverflow questions, but none were useful. Can you show an example? 回答1: Ok this worked for me: ScriptObjectMirror result = (ScriptObjectMirror) function

Nashorn JSON.parse() - java.lang.OutOfMemoryError: Java heap space - JDK8u60

≯℡__Kan透↙ 提交于 2019-12-22 09:48:03
问题 Nashron Release notes claims they fixed the JSON parser bugs, but I am still able to produce a (different) bug on new patch 8u60. This time it is OutOfMemoryError. Refer the attached JSON [1] (it is typically a Category & Subcategory relation). When I try to invoke JSON.parse() it is failing. [1] http://jsfiddle.net/manivannandsekaran/rfftavkz/ I tried to increase the heap size, didn't help, instead of getting the OOM Exception quickly, it delayed bit. When I replace all the integer key with

Running jsdom in Nashorn

爷,独闯天下 提交于 2019-12-21 21:43:27
问题 I want to render d3 charts on the server. I had 3 options: Node, Phantom, and Nashorn. I prefer Nashorn because my API is Scala Play and I don't want to manage another process. (deployment, load, queue, etc etc) So now I need to get JSDom working in Nashorn, so that D3 will have something to render to. This works so far but I can't figure out how to add jsdom class Application @Inject() (val messagesApi: MessagesApi) extends api.ApiController { def test = ApiAction { implicit request => ok(

Use graalvm via the standard JDK 11

前提是你 提交于 2019-12-21 02:42:38
问题 I have project used Nashorn Javascript engine. I'm trying to migrate to java11 and also migrate from Nashorn to Graal. I've read here that I can use graal via the standard JDK installation starting from JDK 11. Also I've read there that Graal-SDK are uploaded to Maven central, and that there is Java flag polyglot.js.nashorn-compat for easy migration. So I've used jdk11, add maven dependency to pom.xml and used java flag but when I'm trying to get engine by name "graal.js", I've got null here:

Java 8 Nashorn: Console pretty unusable

若如初见. 提交于 2019-12-20 11:51:27
问题 I am using Java 8 build 1.8.0-b132 on OSX 10.9.2. I am playing with Nashorn the new JavaScript runtime in Java 8. I am using Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/bin/jjs but unfortunately jjs is pretty unusable in interactive mode since cursor left/right does not work: jjs jjs> var x =^[[D The above output (^[[D) is the result of pressing 'cursor left'. Is there a way to fix that behavior and using cursor left/right in the jjs console? 回答1: Thanks to @assylias for

Interrupt java thread running nashorn script

烈酒焚心 提交于 2019-12-20 10:47:27
问题 In the code below i have javascript running in a separate thread from the main one. That script is an infinite loop, so it needs to be terminated somehow. How? Calling .cancel() is not working AFTER the script begins running. But if i call .cancel() just after the thread initialization, it will terminate it (the commented out line). package testscriptterminate; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; import java.util

how to access methods from my class inside javascript in Nashorn

杀马特。学长 韩版系。学妹 提交于 2019-12-20 05:48:10
问题 In Nashorn it is possible to access predefined classes of java , var ArrayList = Java.type('java.util.ArrayList'); var list = new ArrayList(); list.add('a'); list.add('b'); list.add('c'); Like wise it is possible to access my classes in java script , If so how can it be done and should i be adding my jar in the classpath for referencing it ???? var ArrayList = Java.type('com.example.exa'); 回答1: You must use the -classpath option of jrunscript or jjs . -cp, -classpath (-cp path. Specify where