--- a/nashorn/src/jdk/nashorn/internal/parser/Parser.java Tue Jul 02 14:50:39 2013 +0200
+++ b/nashorn/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<Node> 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");
}
--- a/nashorn/src/jdk/nashorn/internal/runtime/resources/Messages.properties Tue Jul 02 14:50:39 2013 +0200
+++ b/nashorn/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.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/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");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/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<eval>:1:3 Expected l-value but found +
+++ +3
+ ^
+SyntaxError: test/script/basic/JDK-8019553.js#33<eval>:1:3 Expected l-value but found -
+++ -7
+ ^
+SyntaxError: test/script/basic/JDK-8019553.js#33<eval>:1:3 Expected l-value but found +
+-- +2
+ ^
+SyntaxError: test/script/basic/JDK-8019553.js#33<eval>:1:3 Expected l-value but found -
+-- -8
+ ^
--- a/nashorn/test/script/basic/NASHORN-51.js Tue Jul 02 14:50:39 2013 +0200
+++ b/nashorn/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, '/'));
}
}
--- a/nashorn/test/script/basic/NASHORN-51.js.EXPECTED Tue Jul 02 14:50:39 2013 +0200
+++ b/nashorn/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<eval>:1:0 Invalid left hand side for assignment
+1++
+^
+ReferenceError: test/script/basic/NASHORN-51.js#42<eval>:1:0 Invalid left hand side for assignment
+1--
+^
+ReferenceError: test/script/basic/NASHORN-51.js#49<eval>:1:2 Invalid left hand side for assignment
+++1
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#56<eval>:1:2 Invalid left hand side for assignment
+--1
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#35<eval>:1:0 Invalid left hand side for assignment
+0++
+^
+ReferenceError: test/script/basic/NASHORN-51.js#42<eval>:1:0 Invalid left hand side for assignment
+0--
+^
+ReferenceError: test/script/basic/NASHORN-51.js#49<eval>:1:2 Invalid left hand side for assignment
+++0
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#56<eval>:1:2 Invalid left hand side for assignment
+--0
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#35<eval>:1:0 Invalid left hand side for assignment
+3.14++
+^
+ReferenceError: test/script/basic/NASHORN-51.js#42<eval>:1:0 Invalid left hand side for assignment
+3.14--
+^
+ReferenceError: test/script/basic/NASHORN-51.js#49<eval>:1:2 Invalid left hand side for assignment
+++3.14
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#56<eval>:1:2 Invalid left hand side for assignment
+--3.14
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#35<eval>:1:0 Invalid left hand side for assignment
+true++
+^
+ReferenceError: test/script/basic/NASHORN-51.js#42<eval>:1:0 Invalid left hand side for assignment
+true--
+^
+ReferenceError: test/script/basic/NASHORN-51.js#49<eval>:1:2 Invalid left hand side for assignment
+++true
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#56<eval>:1:2 Invalid left hand side for assignment
+--true
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#35<eval>:1:0 Invalid left hand side for assignment
+false++
+^
+ReferenceError: test/script/basic/NASHORN-51.js#42<eval>:1:0 Invalid left hand side for assignment
+false--
+^
+ReferenceError: test/script/basic/NASHORN-51.js#49<eval>:1:2 Invalid left hand side for assignment
+++false
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#56<eval>:1:2 Invalid left hand side for assignment
+--false
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#35<eval>:1:0 Invalid left hand side for assignment
+null++
+^
+ReferenceError: test/script/basic/NASHORN-51.js#42<eval>:1:0 Invalid left hand side for assignment
+null--
+^
+ReferenceError: test/script/basic/NASHORN-51.js#49<eval>:1:2 Invalid left hand side for assignment
+++null
+ ^
+ReferenceError: test/script/basic/NASHORN-51.js#56<eval>:1:2 Invalid left hand side for assignment
+--null
+ ^
--- a/nashorn/test/script/error/NASHORN-57.js.EXPECTED Tue Jul 02 14:50:39 2013 +0200
+++ b/nashorn/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 ;
++;
^