diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index 3c6b71862d5..ffcbf450682 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -223,7 +223,7 @@ public: ScopePusher const* last_function_scope() const { 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 nullptr; @@ -1560,8 +1560,6 @@ NonnullRefPtr 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); } diff --git a/Libraries/LibJS/Tests/regress/using-this-in-default-value-of-arrow-function-parameter.js b/Libraries/LibJS/Tests/regress/using-this-in-default-value-of-arrow-function-parameter.js new file mode 100644 index 00000000000..3143778e593 --- /dev/null +++ b/Libraries/LibJS/Tests/regress/using-this-in-default-value-of-arrow-function-parameter.js @@ -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]); +});