-
Bug
-
Resolution: Won't Fix
-
P3
-
None
-
8u60, 11, 13
-
x86_64
-
generic
A DESCRIPTION OF THE PROBLEM :
When a property lookup is performed on an object backed by a JSObject (or AbstractJSObject) implementation, and the property name contains at least a left parenthesis, the corresponding getMember method is not called by the engine.
In JSObjectLinker, the presence of a left parenthesis seems to be treated as an indication that an exact method with a certain signature should be called on the JSObject instead. However, the main point for implementing a custom JSObject (instead of just exposing a plain Java object) is to control exactly how the object behaves in script code.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
* Extend from AbstractJSObject and override the getMember method.
* Put an instance of that implementation into a Bindings.
* Evaluate a script that tries to access a property name with parentheses.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The custom getMember method is called.
ACTUAL -
The custom getMember method is not called. Instead, the property access expression simply returns null in the script.
---------- BEGIN SOURCE ----------
import javax.script.ScriptEngine;
import jdk.nashorn.api.scripting.AbstractJSObject;
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
public class ParenthesisInPropertyName {
public static class TestJsObject extends AbstractJSObject {
@Override
public Object getMember(String name) {
System.out.println("Member called: " + name);
return null;
}
}
public static void main(String[] args) throws Exception {
ScriptEngine engine = new NashornScriptEngineFactory().getScriptEngine();
engine.put("test", new TestJsObject());
engine.eval("test['foo bar']"); // Member called: foo bar
engine.eval("test['foo(bar)']"); // Nothing happens
}
}
---------- END SOURCE ----------
FREQUENCY : always
When a property lookup is performed on an object backed by a JSObject (or AbstractJSObject) implementation, and the property name contains at least a left parenthesis, the corresponding getMember method is not called by the engine.
In JSObjectLinker, the presence of a left parenthesis seems to be treated as an indication that an exact method with a certain signature should be called on the JSObject instead. However, the main point for implementing a custom JSObject (instead of just exposing a plain Java object) is to control exactly how the object behaves in script code.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
* Extend from AbstractJSObject and override the getMember method.
* Put an instance of that implementation into a Bindings.
* Evaluate a script that tries to access a property name with parentheses.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The custom getMember method is called.
ACTUAL -
The custom getMember method is not called. Instead, the property access expression simply returns null in the script.
---------- BEGIN SOURCE ----------
import javax.script.ScriptEngine;
import jdk.nashorn.api.scripting.AbstractJSObject;
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
public class ParenthesisInPropertyName {
public static class TestJsObject extends AbstractJSObject {
@Override
public Object getMember(String name) {
System.out.println("Member called: " + name);
return null;
}
}
public static void main(String[] args) throws Exception {
ScriptEngine engine = new NashornScriptEngineFactory().getScriptEngine();
engine.put("test", new TestJsObject());
engine.eval("test['foo bar']"); // Member called: foo bar
engine.eval("test['foo(bar)']"); // Nothing happens
}
}
---------- END SOURCE ----------
FREQUENCY : always
- relates to
-
JDK-8055796 JSObject and browser JSObject linkers should provide fallback to call underlying Java methods directly
-
- Resolved
-