Nashorn: JavaScript on the JDK Jim Laskey Multi-language Lead, Language/Tools Group, Java Platform.

download Nashorn: JavaScript on the JDK Jim Laskey Multi-language Lead, Language/Tools Group, Java Platform.

If you can't read please download the document

Transcript of Nashorn: JavaScript on the JDK Jim Laskey Multi-language Lead, Language/Tools Group, Java Platform.

  • Slide 1
  • Nashorn: JavaScript on the JDK Jim Laskey Multi-language Lead, Language/Tools Group, Java Platform
  • Slide 2
  • 2 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 Oracles products remains at the sole discretion of Oracle.
  • Slide 3
  • 3 Multi-language (Nashorn) Team Nashorn: JavaScript for the JVM Dynalink: Meta Object Protocol Node.jar: Nashorn implementation of Node.js
  • Slide 4
  • 4 Multi-language (Nashorn) Team
  • Slide 5
  • 5 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
  • Slide 6
  • 6 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 Formal
  • Slide 7
  • 7 'sup Casual
  • Slide 8
  • 8 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,
  • Slide 9
  • 9 Scripting in the JDK Why 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
  • Slide 10
  • 10 Language Usage http://langpop.corger.nl
  • Slide 11
  • 11 Scripting in the JDK Why 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 Oracles needs Pro: Validation of JSR 292 Con: Not a small effort
  • Slide 12
  • 12 Nashorn JavaScript What 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
  • Slide 13
  • 13 Rhino
  • Slide 14
  • 14 Nashorn
  • Slide 15
  • 15 Nashorn JavaScript Engine Execution Model Compile to byte code Load and execute Compile on demand Type specialization optimization Dynamic linking via Dynalink
  • Slide 16
  • 16 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
  • Slide 17
  • 17 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/ nashornhttp://hg.openjdk.java.net/nashorn/jdk8/ > cd nashorn > sh get_source.sh > sh configure > make all
  • Slide 18
  • 18 How Do You Use Nashorn? Command Line > jjs jjs> var x = 10, y = 20; jjs> x + y; 30 jjs> quit(); Or > jjs example.js
  • Slide 19
  • 19 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) {... }
  • Slide 20
  • 20 Everything is Dynamic get, set, get index, set index, call, and new are all implemented with invokeDynamic Most behaviour can change dynamically
  • Slide 21
  • 21 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
  • Slide 22
  • 22 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
  • Slide 23
  • 23 Dynalink and Nashorn Able to search thru several alternatives Type specific Value conversions Handle overloading Default and special handling Flexibility
  • Slide 24
  • 24 Demos
  • Slide 25
  • 25 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
  • Slide 26
  • 26 Opportunities Development of Nashorn Adding features Performance Eclipse plugins for Nashorn development JavaScript aware, Nashorn extensions aware Debugging tools NashornJDI
  • Slide 27
  • 27 Contacts https://blogs.oracle.com/nashorn/ [email protected] [email protected] @wickund #nashornjs (#nashorn)
  • Slide 28
  • 28 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 Oracles products remains at the sole discretion of Oracle.
  • Slide 29
  • 29