Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8024615

Refactor ScriptObjectMirror and JSObject to support external JSObject implementations

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8
    • 8
    • core-libs
    • None
    • b108
    • generic
    • generic

    Description

      Refactor jdk.nashorn.api.scripting.ScriptObjectMirror and jdk.nashorn.api.scripting.JSObject classes so that the rest of nashorn runtime should use JSObject whenever possible. That way it'd be possible to plugin external JSObject implementations into nashorn. Nashorn's JSObjectLinker would be able to provide easier 'script access' to objects of such classes.

      Example (shown in script - but a JSObject subclass may be implemented in Java as well)

      <pre>

      var JSObject = Java.type("jdk.nashorn.api.scripting.JSObject");
      var global = this;

      var obj = new JSObject() {
          getSlot: function(x) {
              return ++x;
          },

          getMember: function(name) {
              return global[name];
          },

          removeMember: function(name) {
              print("removed " + name);
          }
      };

      print(obj[10]);
      obj.print("hello");
      print(delete obj.foo);

      </pre>

      This provides more or less what JSAdapter provides "proxy" support for script -- except that JSObject subclass can work from Java side as well.

      Attachments

        Activity

          People

            sundar Sundararajan Athijegannathan
            sundar Sundararajan Athijegannathan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: