Questions tagged [scriptengine]

Java's ScriptEngine system allows you to run/evaluate statements written in other programming languages like Javascript/ECMAScript, Python/Jython, and Tcl/Jacl.

227 questions
6
votes
0 answers

IActiveScriptParse32::ParseScriptText Memory Leak

Has anybody ever faced a memory leak problem with IActiveScriptParse32::ParseScriptText when using it in C#? I need a ScriptEngine that is able to parse JavaScript-Code. (Everything works fine, except the used memory) The problem is, that the longer…
xileb0
  • 451
  • 2
  • 6
  • 18
6
votes
1 answer

How do you invoke a method in a Nashorn CompiledScript?

I have the following code which works: ScriptEngine jsEngine = ScriptEngineManager.new().getEngineByName("nashorn"); jsEngine.eval("some script"); jsEngine.invokeMethod(jsEngine.eval("foo"), "bar"); but I want to do use a pre-compiled script so I…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
6
votes
2 answers

Clone Entire JavaScript ScriptEngine

I need to somehow deep clone the entire set of bindings of my ScriptEngine object. What I have tried I have tried so far the Cloner library to clone the entire Bindings structure. This would be great if it worked because it would have ensured a…
Radu Simionescu
  • 4,518
  • 1
  • 35
  • 34
5
votes
3 answers

How to make ScriptEngine to run multiple javascript files?

I have 6 js files and I need to include them all into final script to pass ScriptEngine's eval method.How can I do it? ScriptEngine haven't add() method.I can read them with FileReader and than concatenate those strings but I think there will be a…
shift66
  • 11,760
  • 13
  • 50
  • 83
5
votes
2 answers

How to execute Javascript code from groovy and get the results as a map?

How can I get the results of executed javascript code from groovy? I tried the following, but I always get back the string "world". I would have expected an object or map. import javax.script.ScriptEngineManager import…
Blacktiger
  • 1,275
  • 1
  • 9
  • 19
5
votes
2 answers

unable to execute es6 on java 8 with NashornscriptEngine

I am trying to execute a javascript (ES6) function in java 8 (1.8.0_102). Here is snippet javascript trimmed down. const myfunc = (args) => { if (!(args.name || args.zip)) return const result = {...args} const { name, zip, date } =…
brain storm
  • 30,124
  • 69
  • 225
  • 393
5
votes
2 answers

How to pass Javascript Object from Java to Javascript using Nashorn

I have a JavaScript object in String form (actually coming from database) which I need to pass to a Javascript function using Nashorn (Java 8). The Engine treats the parameter passed as a string in javascript. I want it to identify it as a…
iqz
  • 53
  • 1
  • 6
5
votes
2 answers

ScriptEngineManager and ScriptEngine can not be loaded in Karaf OSGi (Nashorn not found)

I am trying to use ScriptEngineManager and ScriptEngine to execute some JavaScript code with Java. I use Java 8 I am executing this code under Karaf OSGi. The example I used works fine in a sample Java Class, but packing it in a bundle gives me this…
Ali Ben Messaoud
  • 11,690
  • 8
  • 54
  • 87
5
votes
1 answer

PageDown through ScriptEngine incorrectly parsing Markdown

I am trying to use PageDown on the client side as an editor, and on the server side to then parse that Markdown to HTML. It seems to work fine on the client side, but on the server side, tickmarks are only "codifying" the character that follows, not…
Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
5
votes
2 answers

Java Scripting Engine importing my classes does not work

A code is worth 1000 words of explaining it :-) package jasim; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class JSTest { public static void main(String[] args) throws…
Ayman
  • 11,265
  • 16
  • 66
  • 92
5
votes
2 answers

Which JS Script Engine will be chosen by Java?

ScriptEngineManager.getEngineByName looks up and creates a ScriptEngine for a given name. Rhino registers itself as "js", "rhino", "JavaScript", "javascript", "ECMAScript", and "ecmascript" Nashorn registers itself as "nashorn", "Nashorn", "js",…
Ben McCann
  • 18,548
  • 25
  • 83
  • 101
5
votes
1 answer

How do I destroy a Java ScriptEngine Instance?

I'm using Java 8. I'm not a java expert (haven't looked at java since college 10 years ago) I create an instance of a ScriptEngine (Nashorn if it matters). I use it to eval several javascript files. The script chugs along quite happily in its own…
Brent Larsen
  • 1,042
  • 8
  • 10
5
votes
2 answers

Why Java Nashorn __DIR__, __LINE__ and __FILE__ are null?

I am trying to get __DIR__, __LINE__ and __FILE__ Nashorn globals within JavaScript file which is compiled and evaluated by Java Nashorn Engine (JDK 8). However, all of them return NULL... Are they related to some specific Nashorn configuration or?…
user1807754
5
votes
3 answers

Validate JavaScript-Code

I use Java's ScriptEngine to execute JavaScript Code. I use the Invocable Interface, so that I can use the Script Code as a normal Java Object implementing a Java Interface. If the JavaScript Code is invalid does not follow the interface (missing…
Thomas
  • 53
  • 2
  • 4
5
votes
1 answer

How to provide a seperate context on each eval of the java ScriptEngine?

Working on a java based game, using javax.script for AI; public class AI implements Runnable { private boolean alive = true; String scriptStr; ScriptEngine scriptEngine; ScriptContext scriptContext; Bindings engineScope; public AI() { …
hevi
  • 2,432
  • 1
  • 32
  • 51
1
2
3
15 16