mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 20:29:18 +00:00
LibJS: Don't use presence of function params to identify function scope
Instead, we can just use the scope type to determine if a scope is a
function scope.
This fixes using `this` for parameter default values in arrow functions
crashing. This happened by `uses_this_from_environment` was not set in
`set_uses_this`, as it didn't think it was in a function scope whilst
parsing parameters.
Fixes closing modal dialogs causing a crash on https://www.ikea.com/
No test262 diff.
Reverts the functional part of 08cfd5f
, because it was a workaround for
this issue.
This commit is contained in:
parent
26105b8b11
commit
f12b6b258f
Notes:
github-actions[bot]
2025-06-17 18:50:01 +00:00
Author: https://github.com/Lubrsi
Commit: f12b6b258f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5119
Reviewed-by: https://github.com/gmta ✅
2 changed files with 22 additions and 3 deletions
|
@ -223,7 +223,7 @@ public:
|
||||||
ScopePusher const* last_function_scope() const
|
ScopePusher const* last_function_scope() const
|
||||||
{
|
{
|
||||||
for (auto scope_ptr = this; scope_ptr; scope_ptr = scope_ptr->m_parent_scope) {
|
for (auto scope_ptr = this; scope_ptr; scope_ptr = scope_ptr->m_parent_scope) {
|
||||||
if (scope_ptr->m_function_parameters)
|
if (scope_ptr->m_type == ScopeType::Function || scope_ptr->m_type == ScopeType::ClassStaticInit)
|
||||||
return scope_ptr;
|
return scope_ptr;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -1560,8 +1560,6 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
test("using this in default value of arrow function parameter does not crash", () => {
|
||||||
|
const result = [];
|
||||||
|
|
||||||
|
class A {
|
||||||
|
constructor() {
|
||||||
|
this.foo = (bar = this.value1, baz = this.value2, value3 = this.value3) => {
|
||||||
|
result.push(bar);
|
||||||
|
result.push(baz);
|
||||||
|
result.push(value3);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.value1 = 20;
|
||||||
|
this.value2 = 30;
|
||||||
|
this.value3 = 40;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new A().foo(10);
|
||||||
|
|
||||||
|
expect(result).toEqual([10, 30, 40]);
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue