Wed, 17 Jun 2015 14:21:20 +0530
8098847: obj."prop" and obj.'prop' should result in SyntaxError
Reviewed-by: hannesw, attila
1.1 --- a/src/jdk/nashorn/internal/codegen/types/BooleanType.java Tue Jun 16 18:26:25 2015 +0530 1.2 +++ b/src/jdk/nashorn/internal/codegen/types/BooleanType.java Wed Jun 17 14:21:20 2015 +0530 1.3 @@ -1,28 +1,3 @@ 1.4 -/* 1.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 - * 1.8 - * This code is free software; you can redistribute it and/or modify it 1.9 - * under the terms of the GNU General Public License version 2 only, as 1.10 - * published by the Free Software Foundation. Oracle designates this 1.11 - * particular file as subject to the "Classpath" exception as provided 1.12 - * by Oracle in the LICENSE file that accompanied this code. 1.13 - * 1.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 - * version 2 for more details (a copy is included in the LICENSE file that 1.18 - * accompanied this code). 1.19 - * 1.20 - * You should have received a copy of the GNU General Public License version 1.21 - * 2 along with this work; if not, write to the Free Software Foundation, 1.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 - * 1.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 - * or visit www.oracle.com if you need additional information or have any 1.26 - * questions. 1.27 - */ 1.28 - 1.29 /* 1.30 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 1.31 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2.1 --- a/src/jdk/nashorn/internal/parser/AbstractParser.java Tue Jun 16 18:26:25 2015 +0530 2.2 +++ b/src/jdk/nashorn/internal/parser/AbstractParser.java Wed Jun 17 14:21:20 2015 +0530 2.3 @@ -459,6 +459,19 @@ 2.4 if (kind == TokenKind.KEYWORD || kind == TokenKind.FUTURE || kind == TokenKind.FUTURESTRICT) { 2.5 return true; 2.6 } 2.7 + 2.8 + // only literals allowed are null, false and true 2.9 + if (kind == TokenKind.LITERAL) { 2.10 + switch (type) { 2.11 + case FALSE: 2.12 + case NULL: 2.13 + case TRUE: 2.14 + return true; 2.15 + default: 2.16 + return false; 2.17 + } 2.18 + } 2.19 + 2.20 // Fake out identifier. 2.21 final long identToken = Token.recast(token, IDENT); 2.22 // Get IDENT.
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/script/error/JDK-8098847.js Wed Jun 17 14:21:20 2015 +0530 3.3 @@ -0,0 +1,33 @@ 3.4 +/* 3.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/** 3.28 + * JDK-8098847: obj."prop" and obj.'prop' should result in SyntaxError 3.29 + * 3.30 + * @test/compile-error 3.31 + */ 3.32 + 3.33 +var obj = { "prop": 45 }; 3.34 + 3.35 +obj."prop" = "hello"; 3.36 +obj.'prop' = "hello";
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/script/error/JDK-8098847.js.EXPECTED Wed Jun 17 14:21:20 2015 +0530 4.3 @@ -0,0 +1,6 @@ 4.4 +test/script/error/JDK-8098847.js:32:5 Expected ident but found prop 4.5 +obj."prop" = "hello"; 4.6 + ^ 4.7 +test/script/error/JDK-8098847.js:33:5 Expected ident but found prop 4.8 +obj.'prop' = "hello"; 4.9 + ^