summaryrefslogtreecommitdiffstats
path: root/js/src/frontend
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/frontend
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/frontend')
-rw-r--r--js/src/frontend/Parser.cpp34
-rw-r--r--js/src/frontend/Parser.h2
2 files changed, 19 insertions, 17 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);