Bug 1540789 - Correctly scope .this in field initializers. r=jorendorff
authorAshley Hauck <khyperia@mozilla.com>
Wed, 01 May 2019 22:08:47 +0000
changeset 531007 78d0aff2fdc10f4c2485eb921db69ec136e7e178
parent 531006 d0c37d548ba8a450b84d38b3b237a66c03f7f66b
child 531008 b562a1384c61efebb21871410a9053a4bcd8b92a
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1540789
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1540789 - Correctly scope .this in field initializers. r=jorendorff Differential Revision: https://phabricator.services.mozilla.com/D27950
js/src/frontend/Parser.cpp
js/src/jit-test/tests/fields/bug1540789.js
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -7178,22 +7178,16 @@ GeneralParser<ParseHandler, Unit>::synth
     return null();
   }
   handler_.setFunctionFormalParametersAndBody(funNode, argsbody);
   funbox->function()->setArgCount(0);
   tokenStream.setFunctionStart(funbox);
 
   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();
   }
 
   if (!noteUsedName(cx_->names().dotThis)) {
     return null();
   }
@@ -7248,17 +7242,17 @@ GeneralParser<ParseHandler, Unit>::synth
         handler_.newExprStatement(setThis, synthesizedBodyPos.end);
     if (!exprStatement) {
       return null();
     }
 
     handler_.addStatementToList(stmtList, exprStatement);
   }
 
-  auto initializerBody = finishLexicalScope(lexicalScope, stmtList);
+  auto initializerBody = finishLexicalScope(pc_->varScope(), stmtList);
   if (!initializerBody) {
     return null();
   }
   handler_.setBeginPosition(initializerBody, stmtList);
   handler_.setEndPosition(initializerBody, stmtList);
 
   handler_.setFunctionBody(funNode, initializerBody);
 
@@ -7332,27 +7326,17 @@ GeneralParser<ParseHandler, Unit>::field
   funbox->setStart(firstTokenPos.begin, firstTokenLine, firstTokenColumn);
 
   // Push a SourceParseContext on to the stack.
   SourceParseContext funpc(this, funbox, /* newDirectives = */ nullptr);
   if (!funpc.init()) {
     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;
   if (hasInitializer) {
     // Parse the expression for the field initializer.
     initializerExpr = assignExpr(InAllowed, yieldHandling, TripledotProhibited);
     if (!initializerExpr) {
       return null();
@@ -7463,17 +7447,17 @@ GeneralParser<ParseHandler, Unit>::field
   ListNodeType statementList = handler_.newStatementList(wholeInitializerPos);
   if (!argsbody) {
     return null();
   }
   handler_.addStatementToList(statementList, exprStatement);
 
   // Set the function's body to the field assignment.
   LexicalScopeNodeType initializerBody =
-      finishLexicalScope(lexicalScope, statementList);
+      finishLexicalScope(pc_->varScope(), statementList);
   if (!initializerBody) {
     return null();
   }
 
   handler_.setFunctionBody(funNode, initializerBody);
 
   if (!finishFunction(/* isStandaloneFunction = */ false,
                       IsFieldInitializer::Yes)) {
new file mode 100644
--- /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;
+}