mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-23 07:37:29 +09:00
Simplify checking of targets within destructuring patterns.
This commit is contained in:
parent
fd2042225e
commit
33d09dce8b
3 changed files with 14 additions and 82 deletions
|
|
@ -4113,22 +4113,23 @@ Parser<FullParseHandler>::checkDestructuringName(ParseNode* expr, Maybe<Declarat
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise this is an expression in destructuring outside a declaration.
|
// 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)) {
|
if (handler.isNameAnyParentheses(expr)) {
|
||||||
// The arguments/eval identifiers are simple in non-strict mode code.
|
if (const char* chars = handler.nameIsArgumentsEvalAnyParentheses(expr, context)) {
|
||||||
// Warn to discourage their use nonetheless.
|
if (!reportWithNode(ParseStrictError, pc->sc()->strict(), expr,
|
||||||
return reportIfArgumentsEvalTarget(expr);
|
JSMSG_BAD_STRICT_ASSIGN, chars))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nothing further to do for property accesses.
|
if (handler.isPropertyAccess(expr))
|
||||||
MOZ_ASSERT(handler.isPropertyAccess(expr));
|
return true;
|
||||||
return true;
|
|
||||||
|
reportWithNode(ParseError, pc->sc()->strict(), expr, JSMSG_BAD_DESTRUCT_TARGET);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
|
@ -7773,65 +7774,6 @@ Parser<ParseHandler>::isValidSimpleAssignmentTarget(Node node,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
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>
|
template <typename ParseHandler>
|
||||||
bool
|
bool
|
||||||
Parser<ParseHandler>::checkAndMarkAsIncOperand(Node target)
|
Parser<ParseHandler>::checkAndMarkAsIncOperand(Node target)
|
||||||
|
|
|
||||||
|
|
@ -1331,12 +1331,6 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
enum AssignmentFlavor {
|
|
||||||
KeyedDestructuringAssignment,
|
|
||||||
IncrementAssignment,
|
|
||||||
DecrementAssignment,
|
|
||||||
};
|
|
||||||
|
|
||||||
bool matchInOrOf(bool* isForInp, bool* isForOfp);
|
bool matchInOrOf(bool* isForInp, bool* isForOfp);
|
||||||
|
|
||||||
bool hasUsedFunctionSpecialName(HandlePropertyName name);
|
bool hasUsedFunctionSpecialName(HandlePropertyName name);
|
||||||
|
|
@ -1374,9 +1368,6 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
|
||||||
FunctionCallBehavior behavior = ForbidAssignmentToFunctionCalls);
|
FunctionCallBehavior behavior = ForbidAssignmentToFunctionCalls);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool reportIfArgumentsEvalTarget(Node nameNode);
|
|
||||||
bool reportIfNotValidSimpleAssignmentTarget(Node target, AssignmentFlavor flavor);
|
|
||||||
|
|
||||||
bool checkAndMarkAsIncOperand(Node kid);
|
bool checkAndMarkAsIncOperand(Node kid);
|
||||||
bool checkStrictAssignment(Node lhs);
|
bool checkStrictAssignment(Node lhs);
|
||||||
bool checkStrictBinding(PropertyName* name, TokenPos pos);
|
bool checkStrictBinding(PropertyName* name, TokenPos pos);
|
||||||
|
|
|
||||||
|
|
@ -205,7 +205,6 @@ MSG_DEF(JSMSG_BAD_GENEXP_BODY, 1, JSEXN_SYNTAXERR, "illegal use of {0} i
|
||||||
MSG_DEF(JSMSG_BAD_INCOP_OPERAND, 0, JSEXN_SYNTAXERR, "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_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_OCTAL, 1, JSEXN_SYNTAXERR, "{0} is not a legal ECMA-262 octal constant")
|
||||||
MSG_DEF(JSMSG_BAD_OPERAND, 1, JSEXN_SYNTAXERR, "invalid {0} operand")
|
|
||||||
MSG_DEF(JSMSG_BAD_POW_LEFTSIDE, 0, JSEXN_SYNTAXERR, "unparenthesized unary expression can't appear on the left-hand side of '**'")
|
MSG_DEF(JSMSG_BAD_POW_LEFTSIDE, 0, JSEXN_SYNTAXERR, "unparenthesized unary expression can't appear on the left-hand side of '**'")
|
||||||
MSG_DEF(JSMSG_BAD_PROP_ID, 0, JSEXN_SYNTAXERR, "invalid property id")
|
MSG_DEF(JSMSG_BAD_PROP_ID, 0, JSEXN_SYNTAXERR, "invalid property id")
|
||||||
MSG_DEF(JSMSG_BAD_RETURN_OR_YIELD, 1, JSEXN_SYNTAXERR, "{0} not in function")
|
MSG_DEF(JSMSG_BAD_RETURN_OR_YIELD, 1, JSEXN_SYNTAXERR, "{0} not in function")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue