mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-27 01:27:30 +09:00
Report some errors about invalid left-hand-sides in for-in/of loop heads
using code with an explicitly computed offset.
This commit is contained in:
parent
ade86b0f20
commit
71dc0dd5c0
2 changed files with 26 additions and 38 deletions
|
|
@ -5415,37 +5415,6 @@ Parser<ParseHandler>::matchInOrOf(bool* isForInp, bool* isForOfp)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ParseHandler>
|
|
||||||
bool
|
|
||||||
Parser<ParseHandler>::validateForInOrOfLHSExpression(Node target, PossibleError* possibleError)
|
|
||||||
{
|
|
||||||
if (handler.isUnparenthesizedDestructuringPattern(target))
|
|
||||||
return checkDestructuringPattern(target, Nothing(), possibleError);
|
|
||||||
|
|
||||||
// All other permitted targets are simple.
|
|
||||||
if (!reportIfNotValidSimpleAssignmentTarget(target, ForInOrOfTarget))
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (handler.isFunctionCall(target))
|
|
||||||
return checkAssignmentToCall(target, JSMSG_BAD_FOR_LEFTSIDE);
|
|
||||||
|
|
||||||
reportWithNode(ParseError, false, target, JSMSG_BAD_FOR_LEFTSIDE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class ParseHandler>
|
template <class ParseHandler>
|
||||||
bool
|
bool
|
||||||
Parser<ParseHandler>::forHeadStart(YieldHandling yieldHandling,
|
Parser<ParseHandler>::forHeadStart(YieldHandling yieldHandling,
|
||||||
|
|
@ -5526,6 +5495,10 @@ Parser<ParseHandler>::forHeadStart(YieldHandling yieldHandling,
|
||||||
return *forInitialPart != null();
|
return *forInitialPart != null();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t exprOffset;
|
||||||
|
if (!tokenStream.peekOffset(&exprOffset, TokenStream::Operand))
|
||||||
|
return false;
|
||||||
|
|
||||||
// Finally, handle for-loops that start with expressions. Pass
|
// Finally, handle for-loops that start with expressions. Pass
|
||||||
// |InProhibited| so that |in| isn't parsed in a RelationalExpression as a
|
// |InProhibited| so that |in| isn't parsed in a RelationalExpression as a
|
||||||
// binary operator. |in| makes it a for-in loop, *not* an |in| expression.
|
// binary operator. |in| makes it a for-in loop, *not* an |in| expression.
|
||||||
|
|
@ -5569,8 +5542,29 @@ Parser<ParseHandler>::forHeadStart(YieldHandling yieldHandling,
|
||||||
|
|
||||||
*forHeadKind = isForIn ? PNK_FORIN : PNK_FOROF;
|
*forHeadKind = isForIn ? PNK_FORIN : PNK_FOROF;
|
||||||
|
|
||||||
if (!validateForInOrOfLHSExpression(*forInitialPart, &possibleError))
|
// Verify the left-hand side expression doesn't have a forbidden form.
|
||||||
|
if (handler.isUnparenthesizedDestructuringPattern(*forInitialPart)) {
|
||||||
|
if (!checkDestructuringPattern(*forInitialPart, Nothing(), &possibleError))
|
||||||
|
return false;
|
||||||
|
} else if (handler.isNameAnyParentheses(*forInitialPart)) {
|
||||||
|
const char* chars = handler.nameIsArgumentsEvalAnyParentheses(*forInitialPart, context);
|
||||||
|
if (chars) {
|
||||||
|
// |chars| is "arguments" or "eval" here.
|
||||||
|
if (!strictModeErrorAt(exprOffset, JSMSG_BAD_STRICT_ASSIGN, chars))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
handler.adjustGetToSet(*forInitialPart);
|
||||||
|
} else if (handler.isPropertyAccess(*forInitialPart)) {
|
||||||
|
// Permitted: no additional testing/fixup needed.
|
||||||
|
} else if (handler.isFunctionCall(*forInitialPart)) {
|
||||||
|
if (!strictModeErrorAt(exprOffset, JSMSG_BAD_FOR_LEFTSIDE))
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
errorAt(exprOffset, JSMSG_BAD_FOR_LEFTSIDE);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!possibleError.checkForExpressionError())
|
if (!possibleError.checkForExpressionError())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
@ -7869,10 +7863,6 @@ Parser<ParseHandler>::reportIfNotValidSimpleAssignmentTarget(Node target, Assign
|
||||||
case CompoundAssignment:
|
case CompoundAssignment:
|
||||||
errnum = JSMSG_BAD_LEFTSIDE_OF_ASS;
|
errnum = JSMSG_BAD_LEFTSIDE_OF_ASS;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ForInOrOfTarget:
|
|
||||||
errnum = JSMSG_BAD_FOR_LEFTSIDE;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reportWithNode(ParseError, pc->sc()->strict(), target, errnum, extra);
|
reportWithNode(ParseError, pc->sc()->strict(), target, errnum, extra);
|
||||||
|
|
|
||||||
|
|
@ -1139,7 +1139,6 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
|
||||||
Node* forInitialPart,
|
Node* forInitialPart,
|
||||||
mozilla::Maybe<ParseContext::Scope>& forLetImpliedScope,
|
mozilla::Maybe<ParseContext::Scope>& forLetImpliedScope,
|
||||||
Node* forInOrOfExpression);
|
Node* forInOrOfExpression);
|
||||||
bool validateForInOrOfLHSExpression(Node target, PossibleError* possibleError);
|
|
||||||
Node expressionAfterForInOrOf(ParseNodeKind forHeadKind, YieldHandling yieldHandling);
|
Node expressionAfterForInOrOf(ParseNodeKind forHeadKind, YieldHandling yieldHandling);
|
||||||
|
|
||||||
Node switchStatement(YieldHandling yieldHandling);
|
Node switchStatement(YieldHandling yieldHandling);
|
||||||
|
|
@ -1338,7 +1337,6 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
|
||||||
KeyedDestructuringAssignment,
|
KeyedDestructuringAssignment,
|
||||||
IncrementAssignment,
|
IncrementAssignment,
|
||||||
DecrementAssignment,
|
DecrementAssignment,
|
||||||
ForInOrOfTarget
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool checkAndMarkAsAssignmentLhs(Node pn, AssignmentFlavor flavor,
|
bool checkAndMarkAsAssignmentLhs(Node pn, AssignmentFlavor flavor,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue