зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1296814 - Report errors for bad increment/decrement operands using explicitly-specified offsets. r=anba
--HG-- extra : rebase_source : e3b2895fb9f2b8c7aaabb93bc432902185385a59
This commit is contained in:
Родитель
b97bff3170
Коммит
873a735b10
|
@ -7781,31 +7781,28 @@ Parser<ParseHandler>::isValidSimpleAssignmentTarget(Node node,
|
|||
|
||||
template <typename ParseHandler>
|
||||
bool
|
||||
Parser<ParseHandler>::checkAndMarkAsIncOperand(Node target)
|
||||
{
|
||||
if (handler.isNameAnyParentheses(target)) {
|
||||
if (const char* chars = handler.nameIsArgumentsEvalAnyParentheses(target, context)) {
|
||||
if (!reportWithNode(ParseStrictError, pc->sc()->strict(), target,
|
||||
JSMSG_BAD_STRICT_ASSIGN, chars))
|
||||
Parser<ParseHandler>::checkIncDecOperand(Node operand, uint32_t operandOffset)
|
||||
{
|
||||
if (handler.isNameAnyParentheses(operand)) {
|
||||
if (const char* chars = handler.nameIsArgumentsEvalAnyParentheses(operand, context)) {
|
||||
if (!strictModeErrorAt(operandOffset, JSMSG_BAD_STRICT_ASSIGN, chars))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (handler.isPropertyAccess(target)) {
|
||||
} else if (handler.isPropertyAccess(operand)) {
|
||||
// Permitted: no additional testing/fixup needed.
|
||||
} else if (handler.isFunctionCall(target)) {
|
||||
} else if (handler.isFunctionCall(operand)) {
|
||||
// Assignment to function calls is forbidden in ES6. We're still
|
||||
// somewhat concerned about sites using this in dead code, so forbid it
|
||||
// only in strict mode code (or if the werror option has been set), and
|
||||
// otherwise warn.
|
||||
if (!reportWithNode(ParseStrictError, pc->sc()->strict(), target, JSMSG_BAD_INCOP_OPERAND))
|
||||
if (!strictModeErrorAt(operandOffset, JSMSG_BAD_INCOP_OPERAND))
|
||||
return false;
|
||||
} else {
|
||||
reportWithNode(ParseError, pc->sc()->strict(), target, JSMSG_BAD_INCOP_OPERAND);
|
||||
errorAt(operandOffset, JSMSG_BAD_INCOP_OPERAND);
|
||||
return false;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(isValidSimpleAssignmentTarget(target, PermitAssignmentToFunctionCalls),
|
||||
MOZ_ASSERT(isValidSimpleAssignmentTarget(operand, PermitAssignmentToFunctionCalls),
|
||||
"inconsistent increment/decrement operand validation");
|
||||
return true;
|
||||
}
|
||||
|
@ -7870,14 +7867,14 @@ Parser<ParseHandler>::unaryExpr(YieldHandling yieldHandling, TripledotHandling t
|
|||
TokenKind tt2;
|
||||
if (!tokenStream.getToken(&tt2, TokenStream::Operand))
|
||||
return null();
|
||||
Node pn2 = memberExpr(yieldHandling, TripledotProhibited, tt2);
|
||||
if (!pn2)
|
||||
return null();
|
||||
if (!checkAndMarkAsIncOperand(pn2))
|
||||
|
||||
uint32_t operandOffset = pos().begin;
|
||||
Node operand = memberExpr(yieldHandling, TripledotProhibited, tt2);
|
||||
if (!operand || !checkIncDecOperand(operand, operandOffset))
|
||||
return null();
|
||||
|
||||
return handler.newUpdate((tt == TOK_INC) ? PNK_PREINCREMENT : PNK_PREDECREMENT,
|
||||
begin,
|
||||
pn2);
|
||||
begin, operand);
|
||||
}
|
||||
|
||||
case TOK_DELETE: {
|
||||
|
@ -7924,23 +7921,23 @@ Parser<ParseHandler>::unaryExpr(YieldHandling yieldHandling, TripledotHandling t
|
|||
}
|
||||
|
||||
default: {
|
||||
Node pn = memberExpr(yieldHandling, tripledotHandling, tt, /* allowCallSyntax = */ true,
|
||||
Node expr = memberExpr(yieldHandling, tripledotHandling, tt, /* allowCallSyntax = */ true,
|
||||
possibleError, invoked);
|
||||
if (!pn)
|
||||
if (!expr)
|
||||
return null();
|
||||
|
||||
/* Don't look across a newline boundary for a postfix incop. */
|
||||
if (!tokenStream.peekTokenSameLine(&tt))
|
||||
return null();
|
||||
if (tt == TOK_INC || tt == TOK_DEC) {
|
||||
|
||||
if (tt != TOK_INC && tt != TOK_DEC)
|
||||
return expr;
|
||||
|
||||
tokenStream.consumeKnownToken(tt);
|
||||
if (!checkAndMarkAsIncOperand(pn))
|
||||
if (!checkIncDecOperand(expr, begin))
|
||||
return null();
|
||||
return handler.newUpdate((tt == TOK_INC) ? PNK_POSTINCREMENT : PNK_POSTDECREMENT,
|
||||
begin,
|
||||
pn);
|
||||
}
|
||||
return pn;
|
||||
begin, expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1364,7 +1364,7 @@ class Parser final : private JS::AutoGCRooter, public StrictModeGetter
|
|||
FunctionCallBehavior behavior = ForbidAssignmentToFunctionCalls);
|
||||
|
||||
private:
|
||||
bool checkAndMarkAsIncOperand(Node kid);
|
||||
bool checkIncDecOperand(Node operand, uint32_t operandOffset);
|
||||
bool checkStrictAssignment(Node lhs);
|
||||
bool checkStrictBinding(PropertyName* name, TokenPos pos);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче