From 55f2b58badb11ecc318deaf7717048d8b150063f Mon Sep 17 00:00:00 2001 From: Athijegannathan Sundararajan Date: Wed, 17 Jun 2015 14:21:20 +0530 Subject: [PATCH] 8098847: obj."prop" and obj.'prop' should result in SyntaxError Reviewed-by: hannesw, attila --- .../internal/codegen/types/BooleanType.java | 25 -------------- .../internal/parser/AbstractParser.java | 13 ++++++++ nashorn/test/script/error/JDK-8098847.js | 33 +++++++++++++++++++ .../test/script/error/JDK-8098847.js.EXPECTED | 6 ++++ 4 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 nashorn/test/script/error/JDK-8098847.js create mode 100644 nashorn/test/script/error/JDK-8098847.js.EXPECTED diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/types/BooleanType.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/types/BooleanType.java index 234dbdbaca6..9cc239a8436 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/types/BooleanType.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/types/BooleanType.java @@ -23,31 +23,6 @@ * questions. */ -/* - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ - package jdk.nashorn.internal.codegen.types; import static jdk.internal.org.objectweb.asm.Opcodes.I2D; diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/AbstractParser.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/AbstractParser.java index 3eb45cfb853..a7c7fb9e984 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/AbstractParser.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/AbstractParser.java @@ -459,6 +459,19 @@ public abstract class AbstractParser { if (kind == TokenKind.KEYWORD || kind == TokenKind.FUTURE || kind == TokenKind.FUTURESTRICT) { return true; } + + // only literals allowed are null, false and true + if (kind == TokenKind.LITERAL) { + switch (type) { + case FALSE: + case NULL: + case TRUE: + return true; + default: + return false; + } + } + // Fake out identifier. final long identToken = Token.recast(token, IDENT); // Get IDENT. diff --git a/nashorn/test/script/error/JDK-8098847.js b/nashorn/test/script/error/JDK-8098847.js new file mode 100644 index 00000000000..f7d686ca82d --- /dev/null +++ b/nashorn/test/script/error/JDK-8098847.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015, 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-8098847: obj."prop" and obj.'prop' should result in SyntaxError + * + * @test/compile-error + */ + +var obj = { "prop": 45 }; + +obj."prop" = "hello"; +obj.'prop' = "hello"; diff --git a/nashorn/test/script/error/JDK-8098847.js.EXPECTED b/nashorn/test/script/error/JDK-8098847.js.EXPECTED new file mode 100644 index 00000000000..97611acb367 --- /dev/null +++ b/nashorn/test/script/error/JDK-8098847.js.EXPECTED @@ -0,0 +1,6 @@ +test/script/error/JDK-8098847.js:32:5 Expected ident but found prop +obj."prop" = "hello"; + ^ +test/script/error/JDK-8098847.js:33:5 Expected ident but found prop +obj.'prop' = "hello"; + ^