1 / 29

Nashorn: JavaScript on the JDK

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

leia
Download Presentation

Nashorn: JavaScript on the JDK

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  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 Oracle’s products remains at the sole discretion of Oracle.

  3. Multi-language (Nashorn) Team Nashorn: JavaScript for the JVM Dynalink: Meta Object Protocol Node.jar: Nashorn implementation of Node.js

  4. Multi-language (Nashorn) Team

  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

  6. 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

  7. Casual 'sup

  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, …

  9. 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

  10. Language Usagehttp://langpop.corger.nl

  11. 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

  12. 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

  13. Rhino

  14. Nashorn

  15. Nashorn JavaScript EngineExecution Model Compile to byte code Load and execute Compile on demand Type specialization optimization Dynamic linking via Dynalink

  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

  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/nashorn > cd nashorn > shget_source.sh > sh configure > make all

  18. How Do You Use Nashorn? Command Line > jjs jjs> var x = 10, y = 20; jjs> x + y; 30 jjs> quit(); Or > jjsexample.js

  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) { ... }

  20. Everything is Dynamic get, set, get index, set index, call, and new are all implemented with invokeDynamic Most behaviourcan change dynamically

  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

  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

  23. Dynalink and Nashorn Able to search thru several alternatives Type specific Value conversions Handle overloading Default and special handling Flexibility

  24. Demos

  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

  26. Opportunities Development of Nashorn Adding features Performance Eclipse plugins for Nashorn development JavaScript aware, Nashorn extensions aware Debugging tools NashornJDI

  27. Contacts https://blogs.oracle.com/nashorn/ nashorn-dev@openjdk.java.net james.laskey@oracle.com @wickund #nashornjs (#nashorn)

  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 Oracle’s products remains at the sole discretion of Oracle.

More Related