diff options
author | davidot <davidot@serenityos.org> | 2021-11-26 23:36:43 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-11-30 17:05:32 +0000 |
commit | 51e23cd04303e6cd18987d90dec4cc032341b371 (patch) | |
tree | 3f5ca576f3b3b9c32195adb8a4edec096f3cb3da /Userland/Libraries/LibJS/Parser.cpp | |
parent | e491fc0e816bc15d0b7d18bfb8659bab93cd0157 (diff) | |
download | serenity-51e23cd04303e6cd18987d90dec4cc032341b371.zip |
LibJS: Disallow shorthand properties with reserved names
Diffstat (limited to 'Userland/Libraries/LibJS/Parser.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Parser.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 6a43b17824..c8f5690798 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -1497,6 +1497,8 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression() auto lookahead_token = next_token(); if (lookahead_token.type() != TokenType::ParenOpen && lookahead_token.type() != TokenType::Colon + && lookahead_token.type() != TokenType::Comma && lookahead_token.type() != TokenType::CurlyClose + && lookahead_token.type() != TokenType::Async && !lookahead_token.trivia_contains_line_terminator()) { consume(TokenType::Async); function_kind = FunctionKind::Async; @@ -1567,6 +1569,12 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression() } properties.append(create_ast_node<ObjectProperty>({ m_state.current_token.filename(), rule_start.position(), position() }, *property_name, parse_expression(2), property_type, false)); } else if (property_name && property_value) { + if (m_state.strict_mode && is<StringLiteral>(*property_name)) { + auto& string_literal = static_cast<StringLiteral const&>(*property_name); + if (is_strict_reserved_word(string_literal.value())) + syntax_error(String::formatted("'{}' is a reserved keyword", string_literal.value())); + } + properties.append(create_ast_node<ObjectProperty>({ m_state.current_token.filename(), rule_start.position(), position() }, *property_name, *property_value, property_type, false)); } else { expected("a property"); |