diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index 9eed90fc2e34..1d11b460f13c 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -7183,12 +7183,6 @@ GeneralParser::synthesizeConstructor( pc_->functionScope().useAsVarScope(pc_); - // Push a LexicalScope on to the stack. - ParseContext::Scope lexicalScope(this); - if (!lexicalScope.init(pc_)) { - return null(); - } - auto stmtList = handler_.newStatementList(synthesizedBodyPos); if (!stmtList) { return null(); @@ -7253,7 +7247,7 @@ GeneralParser::synthesizeConstructor( handler_.addStatementToList(stmtList, exprStatement); } - auto initializerBody = finishLexicalScope(lexicalScope, stmtList); + auto initializerBody = finishLexicalScope(pc_->varScope(), stmtList); if (!initializerBody) { return null(); } @@ -7337,17 +7331,7 @@ GeneralParser::fieldInitializerOpt( return null(); } - // Push a VarScope on to the stack. - ParseContext::VarScope varScope(this); - if (!varScope.init(pc_)) { - return null(); - } - - // Push a LexicalScope on to the stack. - ParseContext::Scope lexicalScope(this); - if (!lexicalScope.init(pc_)) { - return null(); - } + pc_->functionScope().useAsVarScope(pc_); Node initializerExpr; TokenPos wholeInitializerPos; @@ -7468,7 +7452,7 @@ GeneralParser::fieldInitializerOpt( // Set the function's body to the field assignment. LexicalScopeNodeType initializerBody = - finishLexicalScope(lexicalScope, statementList); + finishLexicalScope(pc_->varScope(), statementList); if (!initializerBody) { return null(); } diff --git a/js/src/jit-test/tests/fields/bug1540789.js b/js/src/jit-test/tests/fields/bug1540789.js new file mode 100644 index 000000000000..6ce647815a49 --- /dev/null +++ b/js/src/jit-test/tests/fields/bug1540789.js @@ -0,0 +1,5 @@ +// |jit-test| --enable-experimental-fields + +class C { + y = () => this.x; +}