aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhannesw <none@none>2014-09-11 18:06:40 +0200
committerhannesw <none@none>2014-09-11 18:06:40 +0200
commitb1064ae49cc97b9eff3b33a974e24693bac4867a (patch)
tree703af5741ab1aee3623922706f6c3aa15d1665bf
parentadc33b6050527a22c000a045c1cea049596c5575 (diff)
8058179: Global constants get in the way of self-modifying properties
Reviewed-by: attila, jlaskey, sundar, lagergren
-rw-r--r--src/jdk/nashorn/internal/runtime/GlobalConstants.java19
-rw-r--r--src/jdk/nashorn/internal/runtime/ScriptObject.java2
-rw-r--r--test/script/basic/JDK-8058179.js48
-rw-r--r--test/script/basic/JDK-8058179.js.EXPECTED4
4 files changed, 62 insertions, 11 deletions
diff --git a/src/jdk/nashorn/internal/runtime/GlobalConstants.java b/src/jdk/nashorn/internal/runtime/GlobalConstants.java
index cc6a2de1..df947cdb 100644
--- a/src/jdk/nashorn/internal/runtime/GlobalConstants.java
+++ b/src/jdk/nashorn/internal/runtime/GlobalConstants.java
@@ -28,6 +28,8 @@ package jdk.nashorn.internal.runtime;
import static jdk.nashorn.internal.codegen.CompilerConstants.staticCall;
import static jdk.nashorn.internal.codegen.CompilerConstants.virtualCall;
import static jdk.nashorn.internal.lookup.Lookup.MH;
+import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.INVALID_PROGRAM_POINT;
+import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.getProgramPoint;
import static jdk.nashorn.internal.runtime.logging.DebugLogger.quote;
import java.lang.invoke.MethodHandle;
@@ -370,22 +372,19 @@ public final class GlobalConstants implements Loggable {
* @param find property lookup
* @param receiver receiver
* @param desc callsite descriptor
- * @param request link request
- * @param operator operator
*
* @return resulting getter, or null if failed to create constant
*/
- synchronized GuardedInvocation findGetMethod(final FindProperty find, final ScriptObject receiver, final CallSiteDescriptor desc, final LinkRequest request, final String operator) {
- if (GLOBAL_ONLY && !find.getOwner().isGlobal()) {
+ synchronized GuardedInvocation findGetMethod(final FindProperty find, final ScriptObject receiver, final CallSiteDescriptor desc) {
+ // Also return null if property may have side effects
+ if ((GLOBAL_ONLY && !find.getOwner().isGlobal()) || find.getProperty() instanceof UserAccessorProperty) {
return null;
}
- final int programPoint = NashornCallSiteDescriptor.isOptimistic(desc) ?
- NashornCallSiteDescriptor.getProgramPoint(desc) :
- UnwarrantedOptimismException.INVALID_PROGRAM_POINT;
- final boolean isOptimistic = programPoint != UnwarrantedOptimismException.INVALID_PROGRAM_POINT;
- final Class<?> retType = desc.getMethodType().returnType();
- final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
+ final boolean isOptimistic = NashornCallSiteDescriptor.isOptimistic(desc);
+ final int programPoint = isOptimistic ? getProgramPoint(desc) : INVALID_PROGRAM_POINT;
+ final Class<?> retType = desc.getMethodType().returnType();
+ final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
final Access acc = getOrCreateSwitchPoint(name);
diff --git a/src/jdk/nashorn/internal/runtime/ScriptObject.java b/src/jdk/nashorn/internal/runtime/ScriptObject.java
index a70957b6..cabd1357 100644
--- a/src/jdk/nashorn/internal/runtime/ScriptObject.java
+++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java
@@ -1971,7 +1971,7 @@ public abstract class ScriptObject implements PropertyAccess {
}
}
- final GuardedInvocation cinv = Global.getConstants().findGetMethod(find, this, desc, request, operator);
+ final GuardedInvocation cinv = Global.getConstants().findGetMethod(find, this, desc);
if (cinv != null) {
return cinv;
}
diff --git a/test/script/basic/JDK-8058179.js b/test/script/basic/JDK-8058179.js
new file mode 100644
index 00000000..1ecd823d
--- /dev/null
+++ b/test/script/basic/JDK-8058179.js
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 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-8058179: Global constants get in the way of self-modifying properties
+ *
+ * @test
+ * @run
+ */
+
+var global = this;
+
+Object.defineProperty(global, "value", {
+ get: function() {
+ print("getting value");
+ global["value"] = "value 2";
+ return "value 1";
+ },
+ set: function(value) {
+ print("setting value: " + value);
+ delete global["value"];
+ global["value"] = value;
+ },
+ configurable: true
+});
+
+print(value);
+print(value);
diff --git a/test/script/basic/JDK-8058179.js.EXPECTED b/test/script/basic/JDK-8058179.js.EXPECTED
new file mode 100644
index 00000000..6d8ed6f6
--- /dev/null
+++ b/test/script/basic/JDK-8058179.js.EXPECTED
@@ -0,0 +1,4 @@
+getting value
+setting value: value 2
+value 1
+value 2