From 22b6014ba6b633b5bf588b6fc7c352181a0a24cb Mon Sep 17 00:00:00 2001 From: Athijegannathan Sundararajan Date: Wed, 3 Jul 2013 00:08:45 +0530 Subject: [PATCH] 8019629: void operator should always evaluate to undefined Reviewed-by: jlaskey --- .../jdk/nashorn/internal/codegen/Attr.java | 5 +-- .../internal/codegen/CodeGenerator.java | 8 ++++ .../jdk/nashorn/internal/ir/RuntimeNode.java | 2 - .../internal/runtime/ScriptRuntime.java | 17 -------- nashorn/test/script/basic/JDK-8019629.js | 42 +++++++++++++++++++ 5 files changed, 51 insertions(+), 23 deletions(-) create mode 100644 nashorn/test/script/basic/JDK-8019629.js diff --git a/nashorn/src/jdk/nashorn/internal/codegen/Attr.java b/nashorn/src/jdk/nashorn/internal/codegen/Attr.java index 3a442a7d8f2..d4b3405fb26 100644 --- a/nashorn/src/jdk/nashorn/internal/codegen/Attr.java +++ b/nashorn/src/jdk/nashorn/internal/codegen/Attr.java @@ -1009,10 +1009,7 @@ final class Attr extends NodeOperatorVisitor { @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)); } /** diff --git a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java index 414d1bb8bc3..d0bf7cd563e 100644 --- a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java +++ b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java @@ -2335,6 +2335,14 @@ final class CodeGenerator extends NodeOperatorVisitor { NEW, /** Typeof operator */ TYPEOF, - /** void type */ - VOID, /** Reference error type */ REFERENCE_ERROR, /** Delete operator */ diff --git a/nashorn/src/jdk/nashorn/internal/runtime/ScriptRuntime.java b/nashorn/src/jdk/nashorn/internal/runtime/ScriptRuntime.java index 15c915cf0e4..1144c57d76d 100644 --- a/nashorn/src/jdk/nashorn/internal/runtime/ScriptRuntime.java +++ b/nashorn/src/jdk/nashorn/internal/runtime/ScriptRuntime.java @@ -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) diff --git a/nashorn/test/script/basic/JDK-8019629.js b/nashorn/test/script/basic/JDK-8019629.js new file mode 100644 index 00000000000..2d284d05150 --- /dev/null +++ b/nashorn/test/script/basic/JDK-8019629.js @@ -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() {}"); +