8062937: Need to block constant assumption for index setters and defineOwnProperty, not just delete

Reviewed-by: hannesw, jlaskey
This commit is contained in:
Marcus Lagergren 2014-11-13 16:59:03 +01:00
parent 20bfcfa75a
commit ebdc046949
3 changed files with 69 additions and 4 deletions

View File

@ -510,6 +510,13 @@ public abstract class ScriptObject implements PropertyAccess {
}
}
private void invalidateGlobalConstant(final String key) {
final GlobalConstants globalConstants = getGlobalConstants();
if (globalConstants != null) {
globalConstants.delete(key);
}
}
/**
* ECMA 8.12.9 [[DefineOwnProperty]] (P, Desc, Throw)
*
@ -525,6 +532,8 @@ public abstract class ScriptObject implements PropertyAccess {
final Object current = getOwnPropertyDescriptor(key);
final String name = JSType.toString(key);
invalidateGlobalConstant(key);
if (current == UNDEFINED) {
if (isExtensible()) {
// add a new own property
@ -923,10 +932,8 @@ public abstract class ScriptObject implements PropertyAccess {
if (property instanceof UserAccessorProperty) {
((UserAccessorProperty)property).setAccessors(this, getMap(), null);
}
final GlobalConstants globalConstants = getGlobalConstants();
if (globalConstants != null) {
globalConstants.delete(property.getKey());
}
invalidateGlobalConstant(property.getKey());
return true;
}
}
@ -3148,6 +3155,9 @@ public abstract class ScriptObject implements PropertyAccess {
*/
public final void setObject(final FindProperty find, final int callSiteFlags, final String key, final Object value) {
FindProperty f = find;
invalidateGlobalConstant(key);
if (f != null && f.isInherited() && !(f.getProperty() instanceof UserAccessorProperty)) {
final boolean isScope = NashornCallSiteDescriptor.isScopeFlag(callSiteFlags);
// If the start object of the find is not this object it means the property was found inside a

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* JDK-8062937 - GlobalConstants produces wrong result with defineProperty and index setters
*
* @test
* @run
*/
var x = 1;
for (var i = 2; i < 5; i++) {
print(x);
Object.defineProperty(this, "x", {value: i});
}
print(x);
print();
var name = "y";
var y = 1;
for (var i = 2; i < 5; i++) {
print(y);
this[name] = i;
}
print(y);

View File

@ -0,0 +1,9 @@
1
2
3
4
1
2
3
4