Details
-
Bug
-
Resolution: Fixed
-
P3
-
8
-
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.
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.