Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-4801

Add support for Nashorn in the JavaScript Scripting Engine

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Later
    • Scripting JavaScript 2.0.16
    • None
    • Scripting
    • None

    Description

      The org.apache.sling.scripting.javascript bundle should attempt to use Nashorn, if available on the user's platform, for running JS code. Alternatively it should switch to Rhino if the JRE is < 1.8.

      Requirements:

      • need to expose the jdk.nashorn.api.scripting;version="0.0.0.1_008_JavaSE" package on JRE >= 1.8 in Sling's launchpad/base/src/main/resources/jre-1.8.properties properties files
      • the Rhino and Nashorn implementations need to co-exist, so that customers still running on Java < 8 can use the Rhino implementation; the switch from Rhino to Nashorn should happen automatically but should also be made configurable in case customers really want to use a specific implementation; while the Nashorn implementation requires Java 8 (and this can easily be handled through the Require-Capability [0] and Bundle-RequiredExecutionEnvironment [1] manifest headers) and the bundle implementing Nashorn support won't start if the detected Java version is < 8, a non-sticky run mode / configuration should handle the switch if customers would still like to use the Rhino implementation on Java >= 8
      • need to find a way to inject custom properties to all instances of a class, similar to Rhino's host objects [2] (thread open on Nashorn's dev list at [3]); this is needed in order to assure JavaScript API backwards compatibility with the JS API exposed through the Rhino implementation currently available in org.apache.sling.scripting.javascript; it seems that Nashorn's public API only allows proxying an object, not all instances of a class

      [0] - http://wiki.osgi.org/wiki/Require-Capability
      [1] - http://wiki.osgi.org/wiki/Bundle-RequiredExecutionEnvironment
      [2] - https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Embedding_tutorial#JavaScript_host_objects
      [3] - http://mail.openjdk.java.net/pipermail/nashorn-dev/2015-June/004751.html

      Attachments

        1. SLING-4801.patch
          412 kB
          Radu Cotescu

        Activity

          People

            radu Radu Cotescu
            radu Radu Cotescu
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: