diff options
author | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-04-06 11:05:22 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-04-06 11:05:22 +0200 |
commit | 74672745e6d1932a4aa7fa6a8cd6ab09fd9de4fe (patch) | |
tree | 5b10fe3716030470a072ffaaab0a66653846afb6 /js/src/frontend | |
parent | 8580bf233e69da042e3d33cad56ca6f42ce441a4 (diff) | |
download | UXP-74672745e6d1932a4aa7fa6a8cd6ab09fd9de4fe.tar UXP-74672745e6d1932a4aa7fa6a8cd6ab09fd9de4fe.tar.gz UXP-74672745e6d1932a4aa7fa6a8cd6ab09fd9de4fe.tar.lz UXP-74672745e6d1932a4aa7fa6a8cd6ab09fd9de4fe.tar.xz UXP-74672745e6d1932a4aa7fa6a8cd6ab09fd9de4fe.zip |
Simplify checking of targets within destructuring patterns.
Diffstat (limited to 'js/src/frontend')
-rw-r--r-- | js/src/frontend/Parser.cpp | 86 | ||||
-rw-r--r-- | js/src/frontend/Parser.h | 9 |
2 files changed, 14 insertions, 81 deletions
diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index 5c4d509dd..3e7c25c19 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -4113,22 +4113,23 @@ Parser<FullParseHandler>::checkDestructuringName(ParseNode* expr, Maybe<Declarat } // Otherwise this is an expression in destructuring outside a declaration. - if (!reportIfNotValidSimpleAssignmentTarget(expr, KeyedDestructuringAssignment)) - return false; - - MOZ_ASSERT(!handler.isFunctionCall(expr), - "function calls shouldn't be considered valid targets in " - "destructuring patterns"); - if (handler.isNameAnyParentheses(expr)) { - // The arguments/eval identifiers are simple in non-strict mode code. - // Warn to discourage their use nonetheless. - return reportIfArgumentsEvalTarget(expr); + if (const char* chars = handler.nameIsArgumentsEvalAnyParentheses(expr, context)) { + if (!reportWithNode(ParseStrictError, pc->sc()->strict(), expr, + JSMSG_BAD_STRICT_ASSIGN, chars)) + { + return false; + } + } + + return true; } - // Nothing further to do for property accesses. - MOZ_ASSERT(handler.isPropertyAccess(expr)); - return true; + if (handler.isPropertyAccess(expr)) + return true; + + reportWithNode(ParseError, pc->sc()->strict(), expr, JSMSG_BAD_DESTRUCT_TARGET); + return false; } template <> @@ -7775,65 +7776,6 @@ Parser<ParseHandler>::isValidSimpleAssignmentTarget(Node node, template <typename ParseHandler> bool -Parser<ParseHandler>::reportIfArgumentsEvalTarget(Node nameNode) -{ - const char* chars = handler.nameIsArgumentsEvalAnyParentheses(nameNode, context); - if (!chars) - return true; - - bool strict = pc->sc()->strict(); - if (!reportWithNode(ParseStrictError, strict, nameNode, JSMSG_BAD_STRICT_ASSIGN, chars)) - return false; - - MOZ_ASSERT(!strict, - "an error should have been reported if this was strict mode " - "code"); - return true; -} - -template <typename ParseHandler> -bool -Parser<ParseHandler>::reportIfNotValidSimpleAssignmentTarget(Node target, AssignmentFlavor flavor) -{ - FunctionCallBehavior behavior = flavor == KeyedDestructuringAssignment - ? ForbidAssignmentToFunctionCalls - : PermitAssignmentToFunctionCalls; - if (isValidSimpleAssignmentTarget(target, behavior)) - return true; - - if (handler.isNameAnyParentheses(target)) { - // Use a special error if the target is arguments/eval. This ensures - // targeting these names is consistently a SyntaxError (which error numbers - // below don't guarantee) while giving us a nicer error message. - if (!reportIfArgumentsEvalTarget(target)) - return false; - } - - unsigned errnum = 0; - const char* extra = nullptr; - - switch (flavor) { - case IncrementAssignment: - errnum = JSMSG_BAD_OPERAND; - extra = "increment"; - break; - - case DecrementAssignment: - errnum = JSMSG_BAD_OPERAND; - extra = "decrement"; - break; - - case KeyedDestructuringAssignment: - errnum = JSMSG_BAD_DESTRUCT_TARGET; - break; - } - - reportWithNode(ParseError, pc->sc()->strict(), target, errnum, extra); - return false; -} - -template <typename ParseHandler> -bool Parser<ParseHandler>::checkAndMarkAsIncOperand(Node target) { if (handler.isNameAnyParentheses(target)) { diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h index c50f8e47d..0baaac3bc 100644 --- a/js/src/frontend/Parser.h +++ b/js/src/frontend/Parser.h @@ -1331,12 +1331,6 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter #endif } - enum AssignmentFlavor { - KeyedDestructuringAssignment, - IncrementAssignment, - DecrementAssignment, - }; - bool matchInOrOf(bool* isForInp, bool* isForOfp); bool hasUsedFunctionSpecialName(HandlePropertyName name); @@ -1374,9 +1368,6 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter FunctionCallBehavior behavior = ForbidAssignmentToFunctionCalls); private: - bool reportIfArgumentsEvalTarget(Node nameNode); - bool reportIfNotValidSimpleAssignmentTarget(Node target, AssignmentFlavor flavor); - bool checkAndMarkAsIncOperand(Node kid); bool checkStrictAssignment(Node lhs); bool checkStrictBinding(PropertyName* name, TokenPos pos); |