changeset 400:313bdcd2fd22

8019629: void operator should always evaluate to undefined Reviewed-by: jlaskey
author sundar
date Wed, 03 Jul 2013 00:08:45 +0530
parents 69ec02d12a31
children 9d3a9fdab668
files src/jdk/nashorn/internal/codegen/Attr.java src/jdk/nashorn/internal/codegen/CodeGenerator.java src/jdk/nashorn/internal/ir/RuntimeNode.java src/jdk/nashorn/internal/runtime/ScriptRuntime.java test/script/basic/JDK-8019629.js
diffstat 5 files changed, 51 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/codegen/Attr.java	Tue Jul 02 15:01:38 2013 +0200
+++ b/src/jdk/nashorn/internal/codegen/Attr.java	Wed Jul 03 00:08:45 2013 +0530
@@ -1009,10 +1009,7 @@
 
     @Override
     public Node leaveVOID(final UnaryNode unaryNode) {
-        final RuntimeNode runtimeNode = (RuntimeNode)new RuntimeNode(unaryNode, Request.VOID).accept(this);
-        assert runtimeNode.getSymbol().getSymbolType().isObject();
-        end(unaryNode);
-        return runtimeNode;
+        return end(ensureSymbol(Type.OBJECT, unaryNode));
     }
 
     /**
--- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Tue Jul 02 15:01:38 2013 +0200
+++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Wed Jul 03 00:08:45 2013 +0530
@@ -2335,6 +2335,14 @@
         return false;
     }
 
+    @Override
+    public boolean enterVOID(final UnaryNode unaryNode) {
+        load(unaryNode.rhs()).pop();
+        method.loadUndefined(Type.OBJECT);
+
+        return false;
+    }
+
     private Node enterNumericAdd(final Node lhs, final Node rhs, final Type type, final Symbol symbol) {
         assert lhs.getType().equals(rhs.getType()) && lhs.getType().equals(type) : lhs.getType() + " != " + rhs.getType() + " != " + type + " " + new ASTWriter(lhs) + " " + new ASTWriter(rhs);
         load(lhs);
--- a/src/jdk/nashorn/internal/ir/RuntimeNode.java	Tue Jul 02 15:01:38 2013 +0200
+++ b/src/jdk/nashorn/internal/ir/RuntimeNode.java	Wed Jul 03 00:08:45 2013 +0530
@@ -53,8 +53,6 @@
         NEW,
         /** Typeof operator */
         TYPEOF,
-        /** void type */
-        VOID,
         /** Reference error type */
         REFERENCE_ERROR,
         /** Delete operator */
--- a/src/jdk/nashorn/internal/runtime/ScriptRuntime.java	Tue Jul 02 15:01:38 2013 +0200
+++ b/src/jdk/nashorn/internal/runtime/ScriptRuntime.java	Wed Jul 03 00:08:45 2013 +0530
@@ -601,23 +601,6 @@
     }
 
     /**
-     * ECMA 11.4.2 - void operator
-     *
-     * @param object object to evaluate
-     *
-     * @return Undefined as the object type
-     */
-    public static Object VOID(final Object object) {
-        if (object instanceof Number) {
-            if (Double.isNaN(((Number)object).doubleValue())) {
-                return Double.NaN;
-            }
-        }
-
-        return UNDEFINED;
-    }
-
-    /**
      * Throw ReferenceError when LHS of assignment or increment/decrement
      * operator is not an assignable node (say a literal)
      *
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/JDK-8019629.js	Wed Jul 03 00:08:45 2013 +0530
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+/**
+ * JDK-8019629: void operator should always evaluate to undefined 
+ *
+ * @test
+ * @run
+ */
+
+function check(str) {
+    var val = eval(str);
+    if (typeof val !== 'undefined') {
+        print("FAILED: " + str + " does not evaluate to 'undefined'");
+    }
+}
+
+check("void +this");
+check("void +(void 0)");
+check("(function f(){return void +(void 0)})()");
+check("void function() {}");
+