mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 01:37:39 +03:00
LibJS: Allow super property lookup and new.target in static init blocks
This commit is contained in:
parent
92672b1520
commit
45578f58dc
Notes:
sideshowbarker
2024-07-17 22:31:33 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/45578f58dc6 Pull-request: https://github.com/SerenityOS/serenity/pull/11316 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/linusg ✅
@ -1200,6 +1200,7 @@ NonnullRefPtr<ClassExpression> Parser::parse_class_expression(bool expect_class_
|
||||
TemporaryChange async_function_context_rollback(m_state.await_expression_is_valid, false);
|
||||
TemporaryChange class_field_initializer_rollback(m_state.in_class_field_initializer, true);
|
||||
TemporaryChange class_static_init_block_rollback(m_state.in_class_static_init_block, true);
|
||||
TemporaryChange super_property_access_rollback(m_state.allow_super_property_lookup, true);
|
||||
|
||||
ScopePusher static_init_scope = ScopePusher::static_init_block_scope(*this, *static_init_block);
|
||||
parse_statement_list(static_init_block);
|
||||
@ -1416,7 +1417,7 @@ Parser::PrimaryExpressionParseResult Parser::parse_primary_expression()
|
||||
auto new_start = position();
|
||||
auto new_target_result = try_parse_new_target_expression();
|
||||
if (!new_target_result.is_null()) {
|
||||
if (!m_state.in_function_context)
|
||||
if (!m_state.in_function_context && !m_state.in_class_static_init_block)
|
||||
syntax_error("'new.target' not allowed outside of a function", new_start);
|
||||
return { new_target_result.release_nonnull() };
|
||||
}
|
||||
|
@ -46,3 +46,29 @@ test("correct this", () => {
|
||||
|
||||
expect(thisValue).toBe(A);
|
||||
});
|
||||
|
||||
describe("class like constructs can be used inside", () => {
|
||||
test("can use new.target", () => {
|
||||
let value = 1;
|
||||
class C {
|
||||
static {
|
||||
value = new.target;
|
||||
}
|
||||
}
|
||||
expect(value).toBeUndefined();
|
||||
});
|
||||
|
||||
test("can use super property lookup", () => {
|
||||
function parent() {}
|
||||
parent.val = 3;
|
||||
|
||||
let hit = false;
|
||||
class C extends parent {
|
||||
static {
|
||||
hit = true;
|
||||
expect(super.val).toBe(3);
|
||||
}
|
||||
}
|
||||
expect(hit).toBeTrue();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user