JDK-8062937 : GlobalConstants produces wrong result with Object.defineProperty
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8u40
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-11-05
  • Updated: 2015-06-04
  • Resolved: 2014-11-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u40Fixed 9 b40Fixed
Related Reports
Blocks :  
Description
var x = 1;
for(var i = 2; i < 5; ++i) {
    print(x);
    Object.defineProperty(this, "x", {value: i });
}
print(x);

Expected result:
1
2
3
4

Observed result:
1
1
1
4

Comments
Basically, any mutation of values in Global that happens outside of a linked named setter will _not_ invalidate the getters linked as constants. This includes ScriptObject.set(), ScriptObject.put(), ScriptObject.addOwnProperty, ScriptObject.modifyOwnProperty, ScriptObject.defineOwnProperty.
05-11-2014

Also: var name = "x"; var x = 1; for(var i = 2; i < 5; ++i) { print(x); this[name] = i; } print(x); prints 1 2 2 4
05-11-2014