mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 01:32:14 -05:00
LibJS: Ensure a function follows an async
identifier in objects
This commit is contained in:
parent
4eda7b5646
commit
a5455ac121
Notes:
github-actions[bot]
2024-12-26 16:24:11 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/a5455ac1219 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3047
2 changed files with 15 additions and 0 deletions
|
@ -2025,6 +2025,7 @@ NonnullRefPtr<ObjectExpression const> Parser::parse_object_expression()
|
||||||
function_kind = FunctionKind::Async;
|
function_kind = FunctionKind::Async;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match(TokenType::Asterisk)) {
|
if (match(TokenType::Asterisk)) {
|
||||||
consume();
|
consume();
|
||||||
property_type = ObjectProperty::Type::KeyValue;
|
property_type = ObjectProperty::Type::KeyValue;
|
||||||
|
@ -2058,6 +2059,7 @@ NonnullRefPtr<ObjectExpression const> Parser::parse_object_expression()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match(TokenType::Equals)) {
|
if (match(TokenType::Equals)) {
|
||||||
// Not a valid object literal, but a valid assignment target
|
// Not a valid object literal, but a valid assignment target
|
||||||
consume();
|
consume();
|
||||||
|
@ -2078,6 +2080,11 @@ NonnullRefPtr<ObjectExpression const> Parser::parse_object_expression()
|
||||||
parse_options |= FunctionNodeParseOptions::IsAsyncFunction;
|
parse_options |= FunctionNodeParseOptions::IsAsyncFunction;
|
||||||
auto function = parse_function_node<FunctionExpression>(parse_options, function_start);
|
auto function = parse_function_node<FunctionExpression>(parse_options, function_start);
|
||||||
properties.append(create_ast_node<ObjectProperty>({ m_source_code, rule_start.position(), position() }, *property_key, function, property_type, true));
|
properties.append(create_ast_node<ObjectProperty>({ m_source_code, rule_start.position(), position() }, *property_key, function, property_type, true));
|
||||||
|
} else if (function_kind == FunctionKind::Async) {
|
||||||
|
// If we previously parsed an `async` keyword, then a function must follow.
|
||||||
|
syntax_error("Expected function after async keyword");
|
||||||
|
skip_to_next_property();
|
||||||
|
continue;
|
||||||
} else if (match(TokenType::Colon)) {
|
} else if (match(TokenType::Colon)) {
|
||||||
if (!property_key) {
|
if (!property_key) {
|
||||||
expected("a property name");
|
expected("a property name");
|
||||||
|
|
|
@ -205,6 +205,14 @@ describe("shorthanded properties with special names", () => {
|
||||||
expect('"use strict"; var await = 8; ({ await, })').toEval();
|
expect('"use strict"; var await = 8; ({ await, })').toEval();
|
||||||
expect('"use strict"; var async = 7; ({ async, })').toEval();
|
expect('"use strict"; var async = 7; ({ async, })').toEval();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("async functions as properties", () => {
|
||||||
|
expect("({ async foo });").not.toEval();
|
||||||
|
expect("({ async foo, });").not.toEval();
|
||||||
|
expect("({ async foo() });").not.toEval();
|
||||||
|
expect("({ async foo: 0 });").not.toEval();
|
||||||
|
expect("({ async foo = 0 });").not.toEval();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("errors", () => {
|
describe("errors", () => {
|
||||||
|
|
Loading…
Reference in a new issue