changeset 397:a7b82e333c31

8016667: Wrong bytecode when testing/setting due to null check shortcut checking against primitive too Reviewed-by: jlaskey, sundar
author lagergren
date Tue, 02 Jul 2013 13:50:19 +0200
parents 5f9abeb0bb50
children 74049fe3ba46 9396e42bae4f
files src/jdk/nashorn/internal/codegen/CodeGenerator.java test/script/basic/JDK-8016667.js
diffstat 2 files changed, 37 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Tue Jul 02 07:45:16 2013 -0300
+++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Tue Jul 02 13:50:19 2013 +0200
@@ -1462,7 +1462,9 @@
             rhs = tmp;
         }
 
-        if (isNullLiteral(rhs)) {
+        // this is a null literal check, so if there is implicit coercion
+        // involved like {D}x=null, we will fail - this is very rare
+        if (isNullLiteral(rhs) && lhs.getType().isObject()) {
             final Label trueLabel  = new Label("trueLabel");
             final Label falseLabel = new Label("falseLabel");
             final Label endLabel   = new Label("end");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/JDK-8016667.js	Tue Jul 02 13:50:19 2013 +0200
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2010, 2013, 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.
+ */
+
+/**
+ * Regression test for erroneous shortcut optimization for object null checks
+ *
+ * @test
+ * @run
+ */
+
+function toto() {
+    var friends = 1;
+    (joe = friends) == null;
+}