8162771: Strict equality operators should not be optimistic
authorhannesw
Tue, 02 Aug 2016 12:39:25 +0200
changeset 40217 88b9823eb989
parent 39922 e613affb88d1
child 40218 3b33c714f2ac
8162771: Strict equality operators should not be optimistic Reviewed-by: jlaskey, sundar
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/OptimisticTypesCalculator.java
nashorn/test/script/basic/JDK-8160034.js
nashorn/test/script/basic/JDK-8162771.js
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/OptimisticTypesCalculator.java	Wed Jul 05 22:01:28 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/OptimisticTypesCalculator.java	Tue Aug 02 12:39:25 2016 +0200
@@ -99,7 +99,9 @@
                     tagNeverOptimistic(binaryNode.rhs());
                 }
             }
-        } else if(binaryNode.isTokenType(TokenType.INSTANCEOF)) {
+        } else if(binaryNode.isTokenType(TokenType.INSTANCEOF)
+                || binaryNode.isTokenType(TokenType.EQ_STRICT)
+                || binaryNode.isTokenType(TokenType.NE_STRICT)) {
             tagNeverOptimistic(binaryNode.lhs());
             tagNeverOptimistic(binaryNode.rhs());
         }
--- a/nashorn/test/script/basic/JDK-8160034.js	Wed Jul 05 22:01:28 2017 +0200
+++ b/nashorn/test/script/basic/JDK-8160034.js	Tue Aug 02 12:39:25 2016 +0200
@@ -22,7 +22,7 @@
  */
 
 /**
- * JDK-8160034.js: The `this` value in the `with` is broken by the repetition of a function call
+ * JDK-8160034: The `this` value in the `with` is broken by the repetition of a function call
  *
  * @test
  * @option --unstable-relink-threshold=4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8162771.js	Tue Aug 02 12:39:25 2016 +0200
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2016, 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-8162771: Strict equality operators should not be optimistic
+ *
+ * @test
+ * @run
+ */
+
+var l = new java.lang.Long(1);
+
+Assert.assertTrue(typeof l === "object");
+Assert.assertTrue(typeof l.longValue() === "object");
+
+Assert.assertTrue(1 == l);
+Assert.assertTrue(1 == l.longValue());
+Assert.assertTrue(l == 1);
+Assert.assertTrue(l.longValue() == 1);
+
+Assert.assertFalse(1 != l);
+Assert.assertFalse(1 != l.longValue());
+Assert.assertFalse(l != 1);
+Assert.assertFalse(l.longValue() != 1);
+
+Assert.assertFalse(1 === l);
+Assert.assertFalse(1 === l.longValue());
+Assert.assertFalse(l === 1);
+Assert.assertFalse(l.longValue() === 1);
+
+Assert.assertTrue(1 !== l);
+Assert.assertTrue(1 !== l.longValue());
+Assert.assertTrue(l !== 1);
+Assert.assertTrue(l.longValue() !== 1);