8019629: void operator should always evaluate to undefined
Reviewed-by: jlaskey
This commit is contained in:
parent
53a84f9d41
commit
22b6014ba6
@ -1009,10 +1009,7 @@ final class Attr extends NodeOperatorVisitor<LexicalContext> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Node leaveVOID(final UnaryNode unaryNode) {
|
public Node leaveVOID(final UnaryNode unaryNode) {
|
||||||
final RuntimeNode runtimeNode = (RuntimeNode)new RuntimeNode(unaryNode, Request.VOID).accept(this);
|
return end(ensureSymbol(Type.OBJECT, unaryNode));
|
||||||
assert runtimeNode.getSymbol().getSymbolType().isObject();
|
|
||||||
end(unaryNode);
|
|
||||||
return runtimeNode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2335,6 +2335,14 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
|
|||||||
return false;
|
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) {
|
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);
|
assert lhs.getType().equals(rhs.getType()) && lhs.getType().equals(type) : lhs.getType() + " != " + rhs.getType() + " != " + type + " " + new ASTWriter(lhs) + " " + new ASTWriter(rhs);
|
||||||
load(lhs);
|
load(lhs);
|
||||||
|
@ -53,8 +53,6 @@ public class RuntimeNode extends Node implements TypeOverride<RuntimeNode> {
|
|||||||
NEW,
|
NEW,
|
||||||
/** Typeof operator */
|
/** Typeof operator */
|
||||||
TYPEOF,
|
TYPEOF,
|
||||||
/** void type */
|
|
||||||
VOID,
|
|
||||||
/** Reference error type */
|
/** Reference error type */
|
||||||
REFERENCE_ERROR,
|
REFERENCE_ERROR,
|
||||||
/** Delete operator */
|
/** Delete operator */
|
||||||
|
@ -600,23 +600,6 @@ public final class ScriptRuntime {
|
|||||||
return JSType.of(obj).typeName();
|
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
|
* Throw ReferenceError when LHS of assignment or increment/decrement
|
||||||
* operator is not an assignable node (say a literal)
|
* operator is not an assignable node (say a literal)
|
||||||
|
42
nashorn/test/script/basic/JDK-8019629.js
Normal file
42
nashorn/test/script/basic/JDK-8019629.js
Normal 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() {}");
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user