8019629: void operator should always evaluate to undefined

Reviewed-by: jlaskey
This commit is contained in:
Athijegannathan Sundararajan 2013-07-03 00:08:45 +05:30
parent 53a84f9d41
commit 22b6014ba6
5 changed files with 51 additions and 23 deletions

View File

@ -1009,10 +1009,7 @@ final class Attr extends NodeOperatorVisitor<LexicalContext> {
@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));
}
/**

View File

@ -2335,6 +2335,14 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
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);

View File

@ -53,8 +53,6 @@ public class RuntimeNode extends Node implements TypeOverride<RuntimeNode> {
NEW,
/** Typeof operator */
TYPEOF,
/** void type */
VOID,
/** Reference error type */
REFERENCE_ERROR,
/** Delete operator */

View File

@ -600,23 +600,6 @@ public final class ScriptRuntime {
return JSType.of(obj).typeName();
}
/**
* 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)

View File

@ -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() {}");