8019629: void operator should always evaluate to undefined
authorsundar
Wed, 03 Jul 2013 00:08:45 +0530
changeset 18838 9b46630f50aa
parent 18634 433fc717df0e
child 18839 adc14dc1ca96
8019629: void operator should always evaluate to undefined Reviewed-by: jlaskey
nashorn/src/jdk/nashorn/internal/codegen/Attr.java
nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java
nashorn/src/jdk/nashorn/internal/ir/RuntimeNode.java
nashorn/src/jdk/nashorn/internal/runtime/ScriptRuntime.java
nashorn/test/script/basic/JDK-8019629.js
--- a/nashorn/src/jdk/nashorn/internal/codegen/Attr.java	Tue Jul 02 15:01:38 2013 +0200
+++ b/nashorn/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/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Tue Jul 02 15:01:38 2013 +0200
+++ b/nashorn/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/nashorn/src/jdk/nashorn/internal/ir/RuntimeNode.java	Tue Jul 02 15:01:38 2013 +0200
+++ b/nashorn/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/nashorn/src/jdk/nashorn/internal/runtime/ScriptRuntime.java	Tue Jul 02 15:01:38 2013 +0200
+++ b/nashorn/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/nashorn/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() {}");
+