nashorn

Add Java-implemented function into Nashorn's global scope

旧巷老猫 提交于 2019-12-06 00:48:50
I'm trying to migrate/update my project to use Nashorn from Rhino. I have some global utility functions implemented in Java and added into global scope of the target script engine, typical example is log(message) . In Rhino it is implemented via public static class LogFunction extends org.mozilla.javascript.BaseFunction { @Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { ... } } whose instance added into target scope. What has to be done in case of Nashorn? I can't find how standalone function can be implemented for Nashorn. You can easily

Avatar.js and Project Avatar

回眸只為那壹抹淺笑 提交于 2019-12-05 22:10:52
问题 In the context of Java 8 and Nashorn I see two projects being regularly mentioned. Avatar.js and Project Avatar What is the relation of these projects? Avatar.js has very little documentation. As far as I gathered it offers the possibility to execute node applications on the JVM. Project Avatar seems to build on Avatar.js. However the scope seems to be to provide an alternative Web-Framework for Java EE 7. Is it also possible to execute node programs (like i.e. grunt) with Project Avatar? 回答1

java11

走远了吗. 提交于 2019-12-05 04:37:58
01. JShell。 (java9 开始支持 ) 02. Dynamic Class-File Constants类文件新添的一种结构 03. 局部变量类型推断(var关键字)。 (java10 开始支持 ) 04. 新加的一些更实用的API 05. 移除的一些其他内容 06. 标准Java异步HTTP客户端。 07. 更简化的编译运行 08. Unicode 10 09. Remove the JavaEE and CORBA Moudles 10. JEP : 335 : Deprecate the Nashorn JavaScript Engine 11. JEP : 336 : Deprecate the Pack200 Tools and API 12. 新的Epsilon垃圾收集器。 13. 新的ZGC垃圾收集器 14. 完全支持Linux容器(包括Docker)。 15. 支持G1上的并行完全垃圾收集。 16. 免费的低耗能堆分析仪。 17. JEP 329 : 实现ChaCha20和Poly1305两种加密算法 18. 新的默认根权限证书集。 19. JEP 332最新的HTTPS安全协议TLS 1.3。 20. Java Flight Recorder 飞行记录仪 1. JShell。 用过Python的童鞋都知道,Python 中的读取-求值-打印循环(

getEngineByName(“nashorn”) returns null

蓝咒 提交于 2019-12-05 02:10:18
Cant get Nashorn engine ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn"); engine.eval("print('Hello World!');"); engine returns null I am using eclipse, jdk1.8.0_11 java -version java version "1.8.0_20-ea" Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b23) Its working when I pass null param into ScriptEngineManager constructor: ScriptEngine engine = new ScriptEngineManager(null).getEngineByName("nashorn"); engine.eval("print('Hello World!');"); from java docs ScriptEngineManager(ClassLoader loader) If loader is null, the script engine factories that are bundled

JDK 1.8.0_92 Nashorn JS engine indexOf behaviour

余生颓废 提交于 2019-12-05 01:46:36
问题 I am using "nashorn" javascript engine in java8 to evaluate some expressions during runtime. I have a util class for this with method: public static String evaluateJavaScriptExpression(String expression) throws ScriptException { if (expression == null) { return null; } ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine javaScriptEngine = scriptEngineManager.getEngineByName(JAVASCRIPT_ENGINE); return String.valueOf(javaScriptEngine.eval(expression)); } for which

readFully not defined with Java Nashorn Javascript Engine

我们两清 提交于 2019-12-04 21:08:15
问题 I am trying to run a javascript script with the new Java 8 Nashorn javascript engine but it fails with the following error: <eval>:1 ReferenceError: "readFully" is not defined The script uses the readFully function that should be defined in the global scope nashorn is run with the scripting mode enabled (wich is default when running through a ScriptEngine as seen here http://mail.openjdk.java.net/pipermail/nashorn-dev/2013-December/002562.html). Here is a sample to reproduce the error: import

How can I pass a proper method reference in so Nashorn can execute it?

只谈情不闲聊 提交于 2019-12-04 18:05:28
I am trying to write a library that will let me execute JSON Logic rules via the Nashorn Javascript engine. My problem right now is specifically around the JSObject wrapper I've created to handle moving data from Java/Kotlin into the scripting engine. If an array is passed in such as [true] it is wrapped and the json-logic script will receive it, see that it is an array, and attempt to run the following bit of code: if(Array.isArray(logic)) { return logic.map(function(l) { return jsonLogic.apply(l, data); }); } When the .map function is called, Nashorn will call getMember("map") on my object

Running jsdom in Nashorn

岁酱吖の 提交于 2019-12-04 15:21:01
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("The API is ready") } def pptx = Action { implicit request => val manager: ScriptEngineManager = new

Effective way to pass JSON between java and javascript

南笙酒味 提交于 2019-12-04 12:30:20
问题 I'm fairly new to Nashorn and scripting on top of the JVM and wanted to know if I can get my java code and javascripts to communicate more effectively. I'm using a 3rd party JS lib that works with JS objects, and in my java code I have the data I want to pass as a Map<String, Object> data . Because that 3rd party JS expects to work with plain JS objects I can't pass my data as is, although the script engine allows you to access a Map as if it was a plain JS object. The script i'm using uses

How to access Java Enums from Javascript (Java 1.8)

纵饮孤独 提交于 2019-12-04 10:02:22
In Java 1.7, prior to it's removal, one could use 'Packages' to access Java Enums in the following way from Javascript on an HTML page viewed a browser: var enumvar1 = document.appletid.Packages.com.mycompany.MyClass$MyEnumYesNo.YES var enumvar2 = document.appletid.Packages.com.mycompany.MyClass$MyEnumYesNo.NO I'm upgrading these HTML pages to use Java 1.8 (which now uses the Nashorn javascript engine), and I cannot seem to figure out how to access the Enum members. I've rewritten the Java applet to return a new MyClass object to a javascript variable, and I can access all the methods and