1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:48:12 +00:00

LibJS: Strict mode assignment to 'eval' & 'arguments' is a syntax error

This commit is contained in:
Matthew Olsson 2020-05-28 07:11:01 -07:00 committed by Andreas Kling
parent 786722149b
commit cbe506020b

View file

@ -816,6 +816,16 @@ NonnullRefPtr<Expression> Parser::parse_secondary_expression(NonnullRefPtr<Expre
syntax_error("Invalid left-hand side in assignment");
return create_ast_node<ErrorExpression>();
}
if (m_parser_state.m_strict_mode && lhs->is_identifier()) {
auto name = static_cast<const Identifier&>(*lhs).string();
if (name == "eval" || name == "arguments") {
syntax_error(
String::format("'%s' cannot be assigned to in strict mode code", name.characters()),
m_parser_state.m_current_token.line_number(),
m_parser_state.m_current_token.line_column()
);
}
}
return create_ast_node<AssignmentExpression>(AssignmentOp::Assignment, move(lhs), parse_expression(min_precedence, associativity));
case TokenType::Period:
consume();