290 likes | 517 Views
Nashorn: JavaScript on the JDK. Jim Laskey Multi-language Lead, Language/Tools Group, Java Platform.
E N D
Nashorn: JavaScript on the JDK Jim Laskey Multi-language Lead, Language/Tools Group, Java Platform
The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions.The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
Multi-language (Nashorn) Team Nashorn: JavaScript for the JVM Dynalink: Meta Object Protocol Node.jar: Nashorn implementation of Node.js
Scripting on the JDK Scripting for Java Access to a huge set of tools and libraries Dynamic programming style Content developer familiarity Rapid prototyping Modifiable post build
Formal James M. Laskey, Esq. EclipseCon 2013 200 Seaport Blvd Boston, MA 02210 March 28, 2013 Attendee EclipseCon 2013 200 Seaport Blvd Boston, MA 02210 Subject: A personal introduction. Dear Sir/Madam, Please allow me this opportunity to offer this introduction to the Nashorn JavaScript engine. This will not take much of your time. Hopefully, you will gain enough insight to consider adding Nashorn to the list of tools you use for your application development. Respectfully, James M. Laskey cc: Eclipse community
Casual 'sup
Origins of Nashorn JavaFX script Adoption issue Rhino Showing age Security issues Not easily adapted to JSR-292 (InvokeDynamic) Other JVM languages Groovy, JRuby, Jython, PHP, Scala, …
Scripting in the JDKWhy JavaScript? Best interest of the JVM to have multiple languages Advances the technology Attracts new developers Choose one JavaScript has a Java-like syntax, but less formal Popularity of JavaScript (HTML5) Applications Client (Extending FX) Embedded/Mobile (light-weight) Server-side scripting (JSP, Business Process) Already using Rhino
Scripting in the JDKWhy Nashorn? Modify Rhino Pro: Reference for all things JavaScript Con: The engine would have to be rewritten for JSR 292 Licensing another JavaScript Pro: Good performance Con: Second VM required, plus a VM to VM API Roll our own Pro: We already have one of the best VMs in the industry Pro: Can be tailored to Oracle’s needs Pro: Validation of JSR 292 Con: Not a small effort
Nashorn JavaScriptWhat is Nashorn? Nashorn is an OpenJDK project to develop a version of ECMAScript-262 to run on the OpenJDK JVM Fully passes test262 (http://test262.ecmascript.org) ES5.1 version of Nashorn will ship with JDK 8 Tracking ES6 with changes included in JDK 8u release Nashorn (pronounced Naz-horn) is the German word for rhinoceros. This is to pay homage to its ancestor, Rhino and the rhinoceros impression on the cover of O'Reilly's JavaScript Definitive Guide Nashorn is written from a clean code base, 100% Java
Nashorn JavaScript EngineExecution Model Compile to byte code Load and execute Compile on demand Type specialization optimization Dynamic linking via Dynalink
How Do I Use Nashorn? Installation As of JDK 8 b82 Nashorn is part of the prerelease http://jdk8.java.net/download.html export PATH=$JAVA_HOME/bin:$PATH export PATH=$JAVA_HOME/jre/bin:$PATH
How Do I Use Nashorn? Build Your Own http://hg.openjdk.java.net/jdk8/build/raw-file/tip/README-builds.html > hg clone http://hg.openjdk.java.net/nashorn/jdk8/nashorn > cd nashorn > shget_source.sh > sh configure > make all
How Do You Use Nashorn? Command Line > jjs jjs> var x = 10, y = 20; jjs> x + y; 30 jjs> quit(); Or > jjsexample.js
How Do You Use Nashorn? javax.script import javax.script.*; ScriptEngineManager m = new ScriptEngineManager(); ScriptEngine e = m.getEngineByName("nashorn"); try { e.eval("print('hello');"); } catch (final ScriptException se) { ... }
Everything is Dynamic get, set, get index, set index, call, and new are all implemented with invokeDynamic Most behaviourcan change dynamically
JSR-292 and invokeDynamic var x = receiver.property; Receiver can be a Nashorn object, a java object, a java bean object, jRuby object, … Look up the best fit
Dynalink Dynalink is an invokedynamic-based high-level linking and meta object protocol library. It enables languages on the JVM to easily interoperate with plain Java objects and each other. Plugins for Nashorn can be constructed for handling special java classes. Ex. java.util.Map – treat maps like objects. https://github.com/szegedi/dynalink
Dynalink and Nashorn Able to search thru several alternatives Type specific Value conversions Handle overloading Default and special handling Flexibility
Node.jar Much of Node.js is native Node.jar native is Java and runs on Nashorn Open sourcing is in the works, stay tuned 0.8.15 working version 0.10.1 conversion in progress
Opportunities Development of Nashorn Adding features Performance Eclipse plugins for Nashorn development JavaScript aware, Nashorn extensions aware Debugging tools NashornJDI
Contacts https://blogs.oracle.com/nashorn/ nashorn-dev@openjdk.java.net james.laskey@oracle.com @wickund #nashornjs (#nashorn)
The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions.The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.