mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-09 02:21:53 +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
6aea459e00
commit
08cfd5ff1b
Notes:
github-actions[bot]
2025-04-05 17:21:29 +00:00
Author: https://github.com/devgianlu
Commit: 08cfd5ff1b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4226
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);
|
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);
|
parse_statement_list(static_init_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,3 +72,20 @@ describe("class like constructs can be used inside", () => {
|
||||||
expect(hit).toBeTrue();
|
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
Add a link
Reference in a new issue