diff options
author | Matthew Olsson <matthewcolsson@gmail.com> | 2020-05-28 07:11:01 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-28 17:18:42 +0200 |
commit | cbe506020bfab2f01539d7b2ce60379e4ae9986b (patch) | |
tree | 61c092124612353876ba6d0689128832ea21f606 /Libraries | |
parent | 786722149b5084dc52be0bdecf2d5628662d0941 (diff) | |
download | serenity-cbe506020bfab2f01539d7b2ce60379e4ae9986b.zip |
LibJS: Strict mode assignment to 'eval' & 'arguments' is a syntax error
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibJS/Parser.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index 2e72f07717..97b46d8db9 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -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(); |