# HG changeset patch # User lagergren # Date 1372770098 -7200 # Node ID 69ec02d12a316701ee67f6ba1dba0e278a548d79 # Parent 9396e42bae4fbb543ee8b98b659e7b6eebd404ab# Parent 74049fe3ba46b1bc55d6d3195968452294a706d4 Merge diff -r 9396e42bae4f -r 69ec02d12a31 src/jdk/nashorn/internal/parser/Parser.java --- a/src/jdk/nashorn/internal/parser/Parser.java Tue Jul 02 14:50:39 2013 +0200 +++ b/src/jdk/nashorn/internal/parser/Parser.java Tue Jul 02 15:01:38 2013 +0200 @@ -535,15 +535,12 @@ if (!(lhs instanceof AccessNode || lhs instanceof IndexNode || lhs instanceof IdentNode)) { - if (env._early_lvalue_error) { - throw error(JSErrorType.REFERENCE_ERROR, AbstractParser.message("invalid.lvalue"), lhs.getToken()); - } - return referenceError(lhs, rhs); + return referenceError(lhs, rhs, env._early_lvalue_error); } if (lhs instanceof IdentNode) { if (!checkIdentLValue((IdentNode)lhs)) { - return referenceError(lhs, rhs); + return referenceError(lhs, rhs, false); } verifyStrictIdent((IdentNode)lhs, "assignment"); } @@ -2617,7 +2614,10 @@ } } - private static RuntimeNode referenceError(final Node lhs, final Node rhs) { + private RuntimeNode referenceError(final Node lhs, final Node rhs, final boolean earlyError) { + if (earlyError) { + throw error(JSErrorType.REFERENCE_ERROR, AbstractParser.message("invalid.lvalue"), lhs.getToken()); + } final ArrayList args = new ArrayList<>(); args.add(lhs); if (rhs == null) { @@ -2695,18 +2695,18 @@ final Node lhs = leftHandSideExpression(); // ++, -- without operand.. if (lhs == null) { - // error would have been issued when looking for 'lhs' - return null; + throw error(AbstractParser.message("expected.lvalue", type.getNameOrType())); } + if (!(lhs instanceof AccessNode || lhs instanceof IndexNode || lhs instanceof IdentNode)) { - return referenceError(lhs, null); + return referenceError(lhs, null, env._early_lvalue_error); } if (lhs instanceof IdentNode) { if (!checkIdentLValue((IdentNode)lhs)) { - return referenceError(lhs, null); + return referenceError(lhs, null, false); } verifyStrictIdent((IdentNode)lhs, "operand for " + opType.getName() + " operator"); } @@ -2725,16 +2725,21 @@ case DECPREFIX: final TokenType opType = type; final Node lhs = expression; + // ++, -- without operand.. + if (lhs == null) { + throw error(AbstractParser.message("expected.lvalue", type.getNameOrType())); + } + if (!(lhs instanceof AccessNode || lhs instanceof IndexNode || lhs instanceof IdentNode)) { next(); - return referenceError(lhs, null); + return referenceError(lhs, null, env._early_lvalue_error); } if (lhs instanceof IdentNode) { if (!checkIdentLValue((IdentNode)lhs)) { next(); - return referenceError(lhs, null); + return referenceError(lhs, null, false); } verifyStrictIdent((IdentNode)lhs, "operand for " + opType.getName() + " operator"); } diff -r 9396e42bae4f -r 69ec02d12a31 src/jdk/nashorn/internal/runtime/resources/Messages.properties --- a/src/jdk/nashorn/internal/runtime/resources/Messages.properties Tue Jul 02 14:50:39 2013 +0200 +++ b/src/jdk/nashorn/internal/runtime/resources/Messages.properties Tue Jul 02 15:01:38 2013 +0200 @@ -43,6 +43,7 @@ parser.error.expected.stmt=Expected statement but found {0} parser.error.expected.comma=Expected comma but found {0} parser.error.expected.property.id=Expected property id but found {0} +parser.error.expected.lvalue=Expected l-value but found {0} parser.error.expected=Expected {0} but found {1} parser.error.invalid.return=Invalid return statement parser.error.no.func.decl.here=Function declarations can only occur at program or function body level. You should use a function expression here instead. diff -r 9396e42bae4f -r 69ec02d12a31 test/script/basic/JDK-8019553.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8019553.js Tue Jul 02 15:01:38 2013 +0200 @@ -0,0 +1,43 @@ +/* + * 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-8019553: NPE on illegal l-value for increment and decrement + * + * @test + * @run + */ + +function check(str) { + try { + eval(str); + fail("SyntaxError expected for: " + str); + } catch (e) { + print(e.toString().replace(/\\/g, '/')); + } +} + +check("++ +3"); +check("++ -7"); +check("-- +2"); +check("-- -8"); diff -r 9396e42bae4f -r 69ec02d12a31 test/script/basic/JDK-8019553.js.EXPECTED --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8019553.js.EXPECTED Tue Jul 02 15:01:38 2013 +0200 @@ -0,0 +1,12 @@ +SyntaxError: test/script/basic/JDK-8019553.js#33:1:3 Expected l-value but found + +++ +3 + ^ +SyntaxError: test/script/basic/JDK-8019553.js#33:1:3 Expected l-value but found - +++ -7 + ^ +SyntaxError: test/script/basic/JDK-8019553.js#33:1:3 Expected l-value but found + +-- +2 + ^ +SyntaxError: test/script/basic/JDK-8019553.js#33:1:3 Expected l-value but found - +-- -8 + ^ diff -r 9396e42bae4f -r 69ec02d12a31 test/script/basic/NASHORN-51.js --- a/test/script/basic/NASHORN-51.js Tue Jul 02 14:50:39 2013 +0200 +++ b/test/script/basic/NASHORN-51.js Tue Jul 02 15:01:38 2013 +0200 @@ -35,28 +35,28 @@ eval(literals[i] + "++"); print("ERROR!! post increment : " + literals[i]); } catch (e) { - print(e); + print(e.toString().replace(/\\/g, '/')); } try { eval(literals[i] + "--"); print("ERROR!! post decrement : " + literals[i]); } catch (e) { - print(e); + print(e.toString().replace(/\\/g, '/')); } try { eval("++" + literals[i]); print("ERROR!! pre increment : " + literals[i]); } catch (e) { - print(e); + print(e.toString().replace(/\\/g, '/')); } try { eval("--" + literals[i]); print("ERROR!! pre decrement : " + literals[i]); } catch (e) { - print(e); + print(e.toString().replace(/\\/g, '/')); } } diff -r 9396e42bae4f -r 69ec02d12a31 test/script/basic/NASHORN-51.js.EXPECTED --- a/test/script/basic/NASHORN-51.js.EXPECTED Tue Jul 02 14:50:39 2013 +0200 +++ b/test/script/basic/NASHORN-51.js.EXPECTED Tue Jul 02 15:01:38 2013 +0200 @@ -1,24 +1,72 @@ -ReferenceError: "1" can not be used as the left-hand side of assignment -ReferenceError: "1" can not be used as the left-hand side of assignment -ReferenceError: "1" can not be used as the left-hand side of assignment -ReferenceError: "1" can not be used as the left-hand side of assignment -ReferenceError: "0" can not be used as the left-hand side of assignment -ReferenceError: "0" can not be used as the left-hand side of assignment -ReferenceError: "0" can not be used as the left-hand side of assignment -ReferenceError: "0" can not be used as the left-hand side of assignment -ReferenceError: "3.14" can not be used as the left-hand side of assignment -ReferenceError: "3.14" can not be used as the left-hand side of assignment -ReferenceError: "3.14" can not be used as the left-hand side of assignment -ReferenceError: "3.14" can not be used as the left-hand side of assignment -ReferenceError: "true" can not be used as the left-hand side of assignment -ReferenceError: "true" can not be used as the left-hand side of assignment -ReferenceError: "true" can not be used as the left-hand side of assignment -ReferenceError: "true" can not be used as the left-hand side of assignment -ReferenceError: "false" can not be used as the left-hand side of assignment -ReferenceError: "false" can not be used as the left-hand side of assignment -ReferenceError: "false" can not be used as the left-hand side of assignment -ReferenceError: "false" can not be used as the left-hand side of assignment -ReferenceError: "null" can not be used as the left-hand side of assignment -ReferenceError: "null" can not be used as the left-hand side of assignment -ReferenceError: "null" can not be used as the left-hand side of assignment -ReferenceError: "null" can not be used as the left-hand side of assignment +ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment +1++ +^ +ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment +1-- +^ +ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment +++1 + ^ +ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment +--1 + ^ +ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment +0++ +^ +ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment +0-- +^ +ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment +++0 + ^ +ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment +--0 + ^ +ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment +3.14++ +^ +ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment +3.14-- +^ +ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment +++3.14 + ^ +ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment +--3.14 + ^ +ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment +true++ +^ +ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment +true-- +^ +ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment +++true + ^ +ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment +--true + ^ +ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment +false++ +^ +ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment +false-- +^ +ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment +++false + ^ +ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment +--false + ^ +ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment +null++ +^ +ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment +null-- +^ +ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment +++null + ^ +ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment +--null + ^ diff -r 9396e42bae4f -r 69ec02d12a31 test/script/error/NASHORN-57.js.EXPECTED --- a/test/script/error/NASHORN-57.js.EXPECTED Tue Jul 02 14:50:39 2013 +0200 +++ b/test/script/error/NASHORN-57.js.EXPECTED Tue Jul 02 15:01:38 2013 +0200 @@ -1,3 +1,3 @@ -test/script/error/NASHORN-57.js:35:2 Expected statement but found ; +test/script/error/NASHORN-57.js:35:2 Expected l-value but found ; ++; ^