mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-26 17:17:31 +09:00
Simplify checking of the left-hand side of assignment and compound
assignment expressions.
This commit is contained in:
parent
d215447209
commit
e9b63ee1fe
2 changed files with 28 additions and 50 deletions
|
|
@ -7470,45 +7470,6 @@ Parser<ParseHandler>::condExpr1(InHandling inHandling, YieldHandling yieldHandli
|
||||||
return handler.newConditional(condition, thenExpr, elseExpr);
|
return handler.newConditional(condition, thenExpr, elseExpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ParseHandler>
|
|
||||||
bool
|
|
||||||
Parser<ParseHandler>::checkAndMarkAsAssignmentLhs(Node target, AssignmentFlavor flavor,
|
|
||||||
PossibleError* possibleError)
|
|
||||||
{
|
|
||||||
MOZ_ASSERT(flavor != KeyedDestructuringAssignment,
|
|
||||||
"destructuring must use special checking/marking code, not "
|
|
||||||
"this method");
|
|
||||||
|
|
||||||
if (handler.isUnparenthesizedDestructuringPattern(target)) {
|
|
||||||
if (flavor == CompoundAssignment) {
|
|
||||||
error(JSMSG_BAD_DESTRUCT_ASS);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return checkDestructuringPattern(target, Nothing(), possibleError);
|
|
||||||
}
|
|
||||||
|
|
||||||
// All other permitted targets are simple.
|
|
||||||
if (!reportIfNotValidSimpleAssignmentTarget(target, flavor))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (handler.isPropertyAccess(target))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (handler.isNameAnyParentheses(target)) {
|
|
||||||
// The arguments/eval identifiers are simple in non-strict mode code,
|
|
||||||
// but warn to discourage use nonetheless.
|
|
||||||
if (!reportIfArgumentsEvalTarget(target))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
handler.adjustGetToSet(target);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
MOZ_ASSERT(handler.isFunctionCall(target));
|
|
||||||
return checkAssignmentToCall(target, JSMSG_BAD_LEFTSIDE_OF_ASS);
|
|
||||||
}
|
|
||||||
|
|
||||||
class AutoClearInDestructuringDecl
|
class AutoClearInDestructuringDecl
|
||||||
{
|
{
|
||||||
ParseContext* pc_;
|
ParseContext* pc_;
|
||||||
|
|
@ -7553,6 +7514,8 @@ Parser<ParseHandler>::assignExpr(InHandling inHandling, YieldHandling yieldHandl
|
||||||
if (!tokenStream.getToken(&tt, TokenStream::Operand))
|
if (!tokenStream.getToken(&tt, TokenStream::Operand))
|
||||||
return null();
|
return null();
|
||||||
|
|
||||||
|
uint32_t exprOffset = pos().begin;
|
||||||
|
|
||||||
bool endsExpr;
|
bool endsExpr;
|
||||||
|
|
||||||
if (tt == TOK_NAME) {
|
if (tt == TOK_NAME) {
|
||||||
|
|
@ -7752,9 +7715,33 @@ Parser<ParseHandler>::assignExpr(InHandling inHandling, YieldHandling yieldHandl
|
||||||
return lhs;
|
return lhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
AssignmentFlavor flavor = kind == PNK_ASSIGN ? PlainAssignment : CompoundAssignment;
|
// Verify the left-hand side expression doesn't have a forbidden form.
|
||||||
if (!checkAndMarkAsAssignmentLhs(lhs, flavor, &possibleErrorInner))
|
if (handler.isUnparenthesizedDestructuringPattern(lhs)) {
|
||||||
|
if (kind != PNK_ASSIGN) {
|
||||||
|
error(JSMSG_BAD_DESTRUCT_ASS);
|
||||||
|
return null();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!checkDestructuringPattern(lhs, Nothing(), &possibleErrorInner))
|
||||||
|
return null();
|
||||||
|
} else if (handler.isNameAnyParentheses(lhs)) {
|
||||||
|
if (const char* chars = handler.nameIsArgumentsEvalAnyParentheses(lhs, context)) {
|
||||||
|
// |chars| is "arguments" or "eval" here.
|
||||||
|
if (!strictModeErrorAt(exprOffset, JSMSG_BAD_STRICT_ASSIGN, chars))
|
||||||
|
return null();
|
||||||
|
}
|
||||||
|
|
||||||
|
handler.adjustGetToSet(lhs);
|
||||||
|
} else if (handler.isPropertyAccess(lhs)) {
|
||||||
|
// Permitted: no additional testing/fixup needed.
|
||||||
|
} else if (handler.isFunctionCall(lhs)) {
|
||||||
|
if (!strictModeErrorAt(exprOffset, JSMSG_BAD_LEFTSIDE_OF_ASS))
|
||||||
|
return null();
|
||||||
|
} else {
|
||||||
|
errorAt(exprOffset, JSMSG_BAD_LEFTSIDE_OF_ASS);
|
||||||
return null();
|
return null();
|
||||||
|
}
|
||||||
|
|
||||||
if (!possibleErrorInner.checkForExpressionError())
|
if (!possibleErrorInner.checkForExpressionError())
|
||||||
return null();
|
return null();
|
||||||
|
|
||||||
|
|
@ -7852,11 +7839,6 @@ Parser<ParseHandler>::reportIfNotValidSimpleAssignmentTarget(Node target, Assign
|
||||||
case KeyedDestructuringAssignment:
|
case KeyedDestructuringAssignment:
|
||||||
errnum = JSMSG_BAD_DESTRUCT_TARGET;
|
errnum = JSMSG_BAD_DESTRUCT_TARGET;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PlainAssignment:
|
|
||||||
case CompoundAssignment:
|
|
||||||
errnum = JSMSG_BAD_LEFTSIDE_OF_ASS;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reportWithNode(ParseError, pc->sc()->strict(), target, errnum, extra);
|
reportWithNode(ParseError, pc->sc()->strict(), target, errnum, extra);
|
||||||
|
|
|
||||||
|
|
@ -1332,15 +1332,11 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
|
||||||
}
|
}
|
||||||
|
|
||||||
enum AssignmentFlavor {
|
enum AssignmentFlavor {
|
||||||
PlainAssignment,
|
|
||||||
CompoundAssignment,
|
|
||||||
KeyedDestructuringAssignment,
|
KeyedDestructuringAssignment,
|
||||||
IncrementAssignment,
|
IncrementAssignment,
|
||||||
DecrementAssignment,
|
DecrementAssignment,
|
||||||
};
|
};
|
||||||
|
|
||||||
bool checkAndMarkAsAssignmentLhs(Node pn, AssignmentFlavor flavor,
|
|
||||||
PossibleError* possibleError=nullptr);
|
|
||||||
bool matchInOrOf(bool* isForInp, bool* isForOfp);
|
bool matchInOrOf(bool* isForInp, bool* isForOfp);
|
||||||
|
|
||||||
bool hasUsedFunctionSpecialName(HandlePropertyName name);
|
bool hasUsedFunctionSpecialName(HandlePropertyName name);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue