LibJS: Require colon in object expression for non-identifier keys

{foo} is valid - {"foo"} or {1} is not.
This commit is contained in:
Linus Groh 2020-04-23 19:17:39 +01:00 committed by Andreas Kling
parent 402ba20c36
commit bebd5c097c
Notes: sideshowbarker 2024-07-19 07:21:02 +09:00

View file

@ -440,8 +440,10 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression()
while (!done() && !match(TokenType::CurlyClose)) {
FlyString property_name;
auto need_colon = true;
if (match_identifier_name()) {
property_name = consume().value();
need_colon = false;
} else if (match(TokenType::StringLiteral)) {
property_name = consume(TokenType::StringLiteral).string_value();
} else if (match(TokenType::NumericLiteral)) {
@ -457,7 +459,7 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression()
continue;
}
if (match(TokenType::Colon)) {
if (need_colon || match(TokenType::Colon)) {
consume(TokenType::Colon);
properties.set(property_name, parse_expression(0));
} else {