mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
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:
parent
308d21b845
commit
adeaf00d88
2 changed files with 19 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue