LibJS: Set empty function parameters on ClassStaticInit scope

This prevents the variables declared inside a class static initializer
to escape to the nearest containing function causing all sorts of memory
corruptions.
This commit is contained in:
devgianlu 2025-03-11 11:15:07 +01:00 committed by Luke Wilde
parent 6aea459e00
commit 08cfd5ff1b
Notes: github-actions[bot] 2025-04-05 17:21:29 +00:00
2 changed files with 19 additions and 0 deletions

View file

@ -1537,6 +1537,8 @@ NonnullRefPtr<ClassExpression const> Parser::parse_class_expression(bool expect_
{
ScopePusher static_init_scope = ScopePusher::static_init_block_scope(*this, *static_init_block);
static_init_scope.set_function_parameters(FunctionParameters::empty());
parse_statement_list(static_init_block);
}

View file

@ -72,3 +72,20 @@ describe("class like constructs can be used inside", () => {
expect(hit).toBeTrue();
});
});
// https://github.com/LadybirdBrowser/ladybird/pull/4226
test("declaring variables", () => {
class A {
static {
const a = 1;
let b = 2;
var c = 3;
function d() {}
expect(a).toBe(1);
expect(b).toBe(2);
expect(c).toBe(3);
expect(typeof d).toBe("function");
}
}
});