-
Bug
-
Resolution: Fixed
-
P4
-
8, 9, 10, 11
-
b11
-
x86_64
-
generic
FULL PRODUCT VERSION :
A DESCRIPTION OF THE PROBLEM :
When using Object.defineProperty to define numeric Properties on a prototype-object setting or reading the value on a derived object ignores these setters and getters.
Using non-numeric properties works, strings containing numeric values don't work.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute script via jjs command line tool:
// ---
if(typeof console == 'object') var print = console.log;
var z = {};
var s = null, g = null;
Object.defineProperty(z,'0',{get:function(){g = 1; return 1;},set:function(v){s = v;}});
var x = Object.create(z);
x['0'] = 6; x['0'];
print("getter (1): "+g);
print("setter (6): "+s);
// ---
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
getter (1): 1
setter (6): 6
nodejs and rhino command line tools produce correct result
ACTUAL -
getter (1): null
setter (6): null
getters and setters seem to be ignored with nashorn
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class BugNashornGetter {
public static void main(String[] args) throws ScriptException {
Object x = new ScriptEngineManager().getEngineByName("js").eval(
"var s = null; var z = {};\n" +
"Object.defineProperty(z,'0',{get:function(){return 5;},set:function(v){s = v;}});\n" +
"var x = Object.create(z);\n" +
"x['0']=3; "+
"s");
System.out.println(x); //Should print 3, but prints null with java 8
}
}
---------- END SOURCE ----------
A DESCRIPTION OF THE PROBLEM :
When using Object.defineProperty to define numeric Properties on a prototype-object setting or reading the value on a derived object ignores these setters and getters.
Using non-numeric properties works, strings containing numeric values don't work.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute script via jjs command line tool:
// ---
if(typeof console == 'object') var print = console.log;
var z = {};
var s = null, g = null;
Object.defineProperty(z,'0',{get:function(){g = 1; return 1;},set:function(v){s = v;}});
var x = Object.create(z);
x['0'] = 6; x['0'];
print("getter (1): "+g);
print("setter (6): "+s);
// ---
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
getter (1): 1
setter (6): 6
nodejs and rhino command line tools produce correct result
ACTUAL -
getter (1): null
setter (6): null
getters and setters seem to be ignored with nashorn
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class BugNashornGetter {
public static void main(String[] args) throws ScriptException {
Object x = new ScriptEngineManager().getEngineByName("js").eval(
"var s = null; var z = {};\n" +
"Object.defineProperty(z,'0',{get:function(){return 5;},set:function(v){s = v;}});\n" +
"var x = Object.create(z);\n" +
"x['0']=3; "+
"s");
System.out.println(x); //Should print 3, but prints null with java 8
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-8204651 setter/getter with numeric property-name
-
- Closed
-