8098847: obj."prop" and obj.'prop' should result in SyntaxError

Reviewed-by: hannesw, attila
This commit is contained in:
Athijegannathan Sundararajan 2015-06-17 14:21:20 +05:30
parent 28f8652430
commit 55f2b58bad
4 changed files with 52 additions and 25 deletions

View File

@ -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;

View File

@ -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.

View File

@ -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";

View File

@ -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";
^