summaryrefslogtreecommitdiffstats
path: root/js/src
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2019-04-06 10:56:39 +0200
committerwolfbeast <mcwerewolf@wolfbeast.com>2019-04-06 10:56:39 +0200
commit8580bf233e69da042e3d33cad56ca6f42ce441a4 (patch)
tree2b02b8b12a8104e1ba5c894b4aa864c6de07454c /js/src
parent194e6155211353738bb14ffd1ca9e9662a455b0e (diff)
downloadUXP-8580bf233e69da042e3d33cad56ca6f42ce441a4.tar
UXP-8580bf233e69da042e3d33cad56ca6f42ce441a4.tar.gz
UXP-8580bf233e69da042e3d33cad56ca6f42ce441a4.tar.lz
UXP-8580bf233e69da042e3d33cad56ca6f42ce441a4.tar.xz
UXP-8580bf233e69da042e3d33cad56ca6f42ce441a4.zip
Simplify increment/decrement operand checking.
Diffstat (limited to 'js/src')
-rw-r--r--js/src/frontend/Parser.cpp34
-rw-r--r--js/src/frontend/Parser.h2
-rw-r--r--js/src/js.msg2
3 files changed, 20 insertions, 18 deletions
diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp
index 041c92fa7..5c4d509dd 100644
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -7834,20 +7834,18 @@ Parser<ParseHandler>::reportIfNotValidSimpleAssignmentTarget(Node target, Assign
template <typename ParseHandler>
bool
-Parser<ParseHandler>::checkAndMarkAsIncOperand(Node target, AssignmentFlavor flavor)
+Parser<ParseHandler>::checkAndMarkAsIncOperand(Node target)
{
- MOZ_ASSERT(flavor == IncrementAssignment || flavor == DecrementAssignment);
-
- // Check.
- if (!reportIfNotValidSimpleAssignmentTarget(target, flavor))
- return false;
-
- // Mark.
if (handler.isNameAnyParentheses(target)) {
- // Assignment to arguments/eval is allowed outside strict mode code,
- // but it's dodgy. Report a strict warning (error, if werror was set).
- if (!reportIfArgumentsEvalTarget(target))
- return false;
+ if (const char* chars = handler.nameIsArgumentsEvalAnyParentheses(target, context)) {
+ if (!reportWithNode(ParseStrictError, pc->sc()->strict(), target,
+ JSMSG_BAD_STRICT_ASSIGN, chars))
+ {
+ return false;
+ }
+ }
+ } else if (handler.isPropertyAccess(target)) {
+ // Permitted: no additional testing/fixup needed.
} else if (handler.isFunctionCall(target)) {
// Assignment to function calls is forbidden in ES6. We're still
// somewhat concerned about sites using this in dead code, so forbid it
@@ -7855,7 +7853,13 @@ Parser<ParseHandler>::checkAndMarkAsIncOperand(Node target, AssignmentFlavor fla
// otherwise warn.
if (!reportWithNode(ParseStrictError, pc->sc()->strict(), target, JSMSG_BAD_INCOP_OPERAND))
return false;
+ } else {
+ reportWithNode(ParseError, pc->sc()->strict(), target, JSMSG_BAD_INCOP_OPERAND);
+ return false;
}
+
+ MOZ_ASSERT(isValidSimpleAssignmentTarget(target, PermitAssignmentToFunctionCalls),
+ "inconsistent increment/decrement operand validation");
return true;
}
@@ -7922,8 +7926,7 @@ Parser<ParseHandler>::unaryExpr(YieldHandling yieldHandling, TripledotHandling t
Node pn2 = memberExpr(yieldHandling, TripledotProhibited, tt2);
if (!pn2)
return null();
- AssignmentFlavor flavor = (tt == TOK_INC) ? IncrementAssignment : DecrementAssignment;
- if (!checkAndMarkAsIncOperand(pn2, flavor))
+ if (!checkAndMarkAsIncOperand(pn2))
return null();
return handler.newUpdate((tt == TOK_INC) ? PNK_PREINCREMENT : PNK_PREDECREMENT,
begin,
@@ -7977,8 +7980,7 @@ Parser<ParseHandler>::unaryExpr(YieldHandling yieldHandling, TripledotHandling t
return null();
if (tt == TOK_INC || tt == TOK_DEC) {
tokenStream.consumeKnownToken(tt);
- AssignmentFlavor flavor = (tt == TOK_INC) ? IncrementAssignment : DecrementAssignment;
- if (!checkAndMarkAsIncOperand(pn, flavor))
+ if (!checkAndMarkAsIncOperand(pn))
return null();
return handler.newUpdate((tt == TOK_INC) ? PNK_POSTINCREMENT : PNK_POSTDECREMENT,
begin,
diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h
index 8bffafc42..c50f8e47d 100644
--- a/js/src/frontend/Parser.h
+++ b/js/src/frontend/Parser.h
@@ -1377,7 +1377,7 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
bool reportIfArgumentsEvalTarget(Node nameNode);
bool reportIfNotValidSimpleAssignmentTarget(Node target, AssignmentFlavor flavor);
- bool checkAndMarkAsIncOperand(Node kid, AssignmentFlavor flavor);
+ bool checkAndMarkAsIncOperand(Node kid);
bool checkStrictAssignment(Node lhs);
bool checkStrictBinding(PropertyName* name, TokenPos pos);
diff --git a/js/src/js.msg b/js/src/js.msg
index a19e3aa85..2901b88cc 100644
--- a/js/src/js.msg
+++ b/js/src/js.msg
@@ -202,7 +202,7 @@ MSG_DEF(JSMSG_LET_STARTING_FOROF_LHS, 0, JSEXN_SYNTAXERR, "an expression X in '
MSG_DEF(JSMSG_BAD_FUNCTION_YIELD, 0, JSEXN_TYPEERR, "can't use 'yield' in a function that can return a value")
MSG_DEF(JSMSG_BAD_GENERATOR_RETURN, 0, JSEXN_TYPEERR, "generator function can't return a value")
MSG_DEF(JSMSG_BAD_GENEXP_BODY, 1, JSEXN_SYNTAXERR, "illegal use of {0} in generator expression")
-MSG_DEF(JSMSG_BAD_INCOP_OPERAND, 0, JSEXN_REFERENCEERR, "invalid increment/decrement operand")
+MSG_DEF(JSMSG_BAD_INCOP_OPERAND, 0, JSEXN_SYNTAXERR, "invalid increment/decrement operand")
MSG_DEF(JSMSG_BAD_METHOD_DEF, 0, JSEXN_SYNTAXERR, "bad method definition")
MSG_DEF(JSMSG_BAD_OCTAL, 1, JSEXN_SYNTAXERR, "{0} is not a legal ECMA-262 octal constant")
MSG_DEF(JSMSG_BAD_OPERAND, 1, JSEXN_SYNTAXERR, "invalid {0} operand")