Bug 1473796 - Part 3: Move DestructuringFlavor into its own header. r=jorendorff
authorTooru Fujisawa <arai_a@mac.com>
Tue, 12 Mar 2019 06:05:21 +0000
changeset 521490 7e1e3f35d7cf58e25bdc0753c0f5a235e55bf08f
parent 521489 d20d700c80d59dd1c4a7a31db50319227cf3ede7
child 521491 2429f6898afa1a763a5dfd3a76d42b2e7267d074
push id10866
push usernerli@mozilla.com
push dateTue, 12 Mar 2019 18:59:09 +0000
treeherdermozilla-beta@445c24a51727 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1473796
milestone67.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 1473796 - Part 3: Move DestructuringFlavor into its own header. r=jorendorff Differential Revision: https://phabricator.services.mozilla.com/D19621
js/src/frontend/BytecodeEmitter.cpp
js/src/frontend/BytecodeEmitter.h
js/src/frontend/DestructuringFlavor.h
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -2713,33 +2713,33 @@ bool BytecodeEmitter::emitSetOrInitializ
     }
   } else {
     switch (target->getKind()) {
       case ParseNodeKind::Name: {
         RootedAtom name(cx, target->as<NameNode>().name());
         NameLocation loc;
         NameOpEmitter::Kind kind;
         switch (flav) {
-          case DestructuringDeclaration:
+          case DestructuringFlavor::Declaration:
             loc = lookupName(name);
             kind = NameOpEmitter::Kind::Initialize;
             break;
-          case DestructuringFormalParameterInVarScope: {
+          case DestructuringFlavor::FormalParameterInVarScope: {
             // If there's an parameter expression var scope, the
             // destructuring declaration needs to initialize the name in
             // the function scope. The innermost scope is the var scope,
             // and its enclosing scope is the function scope.
             EmitterScope* funScope =
                 innermostEmitterScope()->enclosingInFrame();
             loc = *locationOfNameBoundInScope(name, funScope);
             kind = NameOpEmitter::Kind::Initialize;
             break;
           }
 
-          case DestructuringAssignment:
+          case DestructuringFlavor::Assignment:
             loc = lookupName(name);
             kind = NameOpEmitter::Kind::SimpleAssignment;
             break;
         }
 
         NameOpEmitter noe(this, name, loc, kind);
         if (!noe.prepareForRhs()) {
           //        [stack] V ENV?
@@ -4042,17 +4042,17 @@ bool BytecodeEmitter::emitDeclarationLis
       if (!markStepBreakpoint()) {
         return false;
       }
       if (!emitTree(initializer)) {
         return false;
       }
 
       if (!emitDestructuringOps(&pattern->as<ListNode>(),
-                                DestructuringDeclaration)) {
+                                DestructuringFlavor::Declaration)) {
         return false;
       }
 
       if (!emit1(JSOP_POP)) {
         return false;
       }
     }
   }
@@ -4395,17 +4395,17 @@ bool BytecodeEmitter::emitAssignment(Par
       }
 
       eoe.reset();
       break;
     }
     case ParseNodeKind::ArrayExpr:
     case ParseNodeKind::ObjectExpr:
       if (!emitDestructuringOps(&lhs->as<ListNode>(),
-                                DestructuringAssignment)) {
+                                DestructuringFlavor::Assignment)) {
         return false;
       }
       break;
     default:
       MOZ_ASSERT(0);
   }
   return true;
 }
@@ -4619,17 +4619,17 @@ bool BytecodeEmitter::emitCatch(BinaryNo
     if (!emit1(JSOP_POP)) {
       return false;
     }
   } else {
     switch (param->getKind()) {
       case ParseNodeKind::ArrayExpr:
       case ParseNodeKind::ObjectExpr:
         if (!emitDestructuringOps(&param->as<ListNode>(),
-                                  DestructuringDeclaration)) {
+                                  DestructuringFlavor::Declaration)) {
           return false;
         }
         if (!emit1(JSOP_POP)) {
           return false;
         }
         break;
 
       case ParseNodeKind::Name:
@@ -5344,17 +5344,17 @@ bool BytecodeEmitter::emitInitializeForI
 
   MOZ_ASSERT(
       !target->isKind(ParseNodeKind::AssignExpr),
       "for-in/of loop destructuring declarations can't have initializers");
 
   MOZ_ASSERT(target->isKind(ParseNodeKind::ArrayExpr) ||
              target->isKind(ParseNodeKind::ObjectExpr));
   return emitDestructuringOps(&target->as<ListNode>(),
-                              DestructuringDeclaration);
+                              DestructuringFlavor::Declaration);
 }
 
 bool BytecodeEmitter::emitForOf(ForNode* forOfLoop,
                                 const EmitterScope* headLexicalEmitterScope) {
   MOZ_ASSERT(forOfLoop->isKind(ParseNodeKind::ForStmt));
 
   TernaryNode* forOfHead = forOfLoop->head();
   MOZ_ASSERT(forOfHead->isKind(ParseNodeKind::ForOf));
@@ -8517,20 +8517,20 @@ bool BytecodeEmitter::emitFunctionFormal
       // already on the stack.
       if (!initializer && !isRest && !emitArgOp(JSOP_GETARG, argSlot)) {
         return false;
       }
 
       // If there's an parameter expression var scope, the destructuring
       // declaration needs to initialize the name in the function scope,
       // which is not the innermost scope.
-      if (!emitDestructuringOps(&bindingElement->as<ListNode>(),
-                                paramExprVarScope
-                                    ? DestructuringFormalParameterInVarScope
-                                    : DestructuringDeclaration)) {
+      if (!emitDestructuringOps(
+              &bindingElement->as<ListNode>(),
+              paramExprVarScope ? DestructuringFlavor::FormalParameterInVarScope
+                                : DestructuringFlavor::Declaration)) {
         return false;
       }
 
       if (!emit1(JSOP_POP)) {
         return false;
       }
     } else if (hasParameterExprs || isRest) {
       RootedAtom paramName(cx, bindingElement->as<NameNode>().name());
--- a/js/src/frontend/BytecodeEmitter.h
+++ b/js/src/frontend/BytecodeEmitter.h
@@ -9,16 +9,17 @@
 #ifndef frontend_BytecodeEmitter_h
 #define frontend_BytecodeEmitter_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/Span.h"
 
 #include "ds/InlineTable.h"
 #include "frontend/BCEParserHandle.h"
+#include "frontend/DestructuringFlavor.h"
 #include "frontend/EitherParser.h"
 #include "frontend/JumpList.h"
 #include "frontend/NameFunctions.h"
 #include "frontend/ParseNode.h"
 #include "frontend/SharedContext.h"
 #include "frontend/SourceNotes.h"
 #include "frontend/ValueUsage.h"
 #include "vm/BytecodeUtil.h"
@@ -688,31 +689,16 @@ struct MOZ_STACK_CLASS BytecodeEmitter {
       LexicalScopeNode* lexicalScope);
   MOZ_MUST_USE bool emitLexicalScopeBody(
       ParseNode* body, EmitLineNumberNote emitLineNote = EMIT_LINENOTE);
   MOZ_NEVER_INLINE MOZ_MUST_USE bool emitSwitch(SwitchStatement* switchStmt);
   MOZ_NEVER_INLINE MOZ_MUST_USE bool emitTry(TryNode* tryNode);
 
   MOZ_MUST_USE bool emitGoSub(JumpList* jump);
 
-  enum DestructuringFlavor {
-    // Destructuring into a declaration.
-    DestructuringDeclaration,
-
-    // Destructuring into a formal parameter, when the formal parameters
-    // contain an expression that might be evaluated, and thus require
-    // this destructuring to assign not into the innermost scope that
-    // contains the function body's vars, but into its enclosing scope for
-    // parameter expressions.
-    DestructuringFormalParameterInVarScope,
-
-    // Destructuring as part of an AssignmentExpression.
-    DestructuringAssignment
-  };
-
   // emitDestructuringLHSRef emits the lhs expression's reference.
   // If the lhs expression is object property |OBJ.prop|, it emits |OBJ|.
   // If it's object element |OBJ[ELEM]|, it emits |OBJ| and |ELEM|.
   // If there's nothing to evaluate for the reference, it emits nothing.
   // |emitted| parameter receives the number of values pushed onto the stack.
   MOZ_MUST_USE bool emitDestructuringLHSRef(ParseNode* target, size_t* emitted);
 
   // emitSetOrInitializeDestructuring assumes the lhs expression's reference
new file mode 100644
--- /dev/null
+++ b/js/src/frontend/DestructuringFlavor.h
@@ -0,0 +1,31 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: set ts=8 sts=2 et sw=2 tw=80:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef frontend_DestructuringFlavor_h
+#define frontend_DestructuringFlavor_h
+
+namespace js {
+namespace frontend {
+
+enum class DestructuringFlavor {
+  // Destructuring into a declaration.
+  Declaration,
+
+  // Destructuring into a formal parameter, when the formal parameters
+  // contain an expression that might be evaluated, and thus require
+  // this destructuring to assign not into the innermost scope that
+  // contains the function body's vars, but into its enclosing scope for
+  // parameter expressions.
+  FormalParameterInVarScope,
+
+  // Destructuring as part of an AssignmentExpression.
+  Assignment
+};
+
+} /* namespace frontend */
+} /* namespace js */
+
+#endif /* frontend_DestructuringFlavor_h */