Wed, 03 Jul 2013 00:08:45 +0530
8019629: void operator should always evaluate to undefined
Reviewed-by: jlaskey
1.1 --- a/src/jdk/nashorn/internal/codegen/Attr.java Tue Jul 02 15:01:38 2013 +0200 1.2 +++ b/src/jdk/nashorn/internal/codegen/Attr.java Wed Jul 03 00:08:45 2013 +0530 1.3 @@ -1009,10 +1009,7 @@ 1.4 1.5 @Override 1.6 public Node leaveVOID(final UnaryNode unaryNode) { 1.7 - final RuntimeNode runtimeNode = (RuntimeNode)new RuntimeNode(unaryNode, Request.VOID).accept(this); 1.8 - assert runtimeNode.getSymbol().getSymbolType().isObject(); 1.9 - end(unaryNode); 1.10 - return runtimeNode; 1.11 + return end(ensureSymbol(Type.OBJECT, unaryNode)); 1.12 } 1.13 1.14 /**
2.1 --- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java Tue Jul 02 15:01:38 2013 +0200 2.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java Wed Jul 03 00:08:45 2013 +0530 2.3 @@ -2335,6 +2335,14 @@ 2.4 return false; 2.5 } 2.6 2.7 + @Override 2.8 + public boolean enterVOID(final UnaryNode unaryNode) { 2.9 + load(unaryNode.rhs()).pop(); 2.10 + method.loadUndefined(Type.OBJECT); 2.11 + 2.12 + return false; 2.13 + } 2.14 + 2.15 private Node enterNumericAdd(final Node lhs, final Node rhs, final Type type, final Symbol symbol) { 2.16 assert lhs.getType().equals(rhs.getType()) && lhs.getType().equals(type) : lhs.getType() + " != " + rhs.getType() + " != " + type + " " + new ASTWriter(lhs) + " " + new ASTWriter(rhs); 2.17 load(lhs);
3.1 --- a/src/jdk/nashorn/internal/ir/RuntimeNode.java Tue Jul 02 15:01:38 2013 +0200 3.2 +++ b/src/jdk/nashorn/internal/ir/RuntimeNode.java Wed Jul 03 00:08:45 2013 +0530 3.3 @@ -53,8 +53,6 @@ 3.4 NEW, 3.5 /** Typeof operator */ 3.6 TYPEOF, 3.7 - /** void type */ 3.8 - VOID, 3.9 /** Reference error type */ 3.10 REFERENCE_ERROR, 3.11 /** Delete operator */
4.1 --- a/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Tue Jul 02 15:01:38 2013 +0200 4.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Wed Jul 03 00:08:45 2013 +0530 4.3 @@ -601,23 +601,6 @@ 4.4 } 4.5 4.6 /** 4.7 - * ECMA 11.4.2 - void operator 4.8 - * 4.9 - * @param object object to evaluate 4.10 - * 4.11 - * @return Undefined as the object type 4.12 - */ 4.13 - public static Object VOID(final Object object) { 4.14 - if (object instanceof Number) { 4.15 - if (Double.isNaN(((Number)object).doubleValue())) { 4.16 - return Double.NaN; 4.17 - } 4.18 - } 4.19 - 4.20 - return UNDEFINED; 4.21 - } 4.22 - 4.23 - /** 4.24 * Throw ReferenceError when LHS of assignment or increment/decrement 4.25 * operator is not an assignable node (say a literal) 4.26 *
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/script/basic/JDK-8019629.js Wed Jul 03 00:08:45 2013 +0530 5.3 @@ -0,0 +1,42 @@ 5.4 +/* 5.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.23 + * or visit www.oracle.com if you need additional information or have any 5.24 + * questions. 5.25 + */ 5.26 + 5.27 +/** 5.28 + * JDK-8019629: void operator should always evaluate to undefined 5.29 + * 5.30 + * @test 5.31 + * @run 5.32 + */ 5.33 + 5.34 +function check(str) { 5.35 + var val = eval(str); 5.36 + if (typeof val !== 'undefined') { 5.37 + print("FAILED: " + str + " does not evaluate to 'undefined'"); 5.38 + } 5.39 +} 5.40 + 5.41 +check("void +this"); 5.42 +check("void +(void 0)"); 5.43 +check("(function f(){return void +(void 0)})()"); 5.44 +check("void function() {}"); 5.45 +