Bug 1466000 - Part 2: Move call context handling from BytecodeEmitter::emitGetNameAtLocation to BytecodeEmitter::emitCalleeAndThis. r=efaust
authorTooru Fujisawa <arai_a@mac.com>
Tue, 09 Oct 2018 21:23:11 +0900
changeset 498911 1674f2fff9a61718e6a198a644d279f9aa06f670
parent 498910 0ed41dadd8cff2a4f9585dc250a6fcf1995a193c
child 498912 b1c3a4c98e406a6b1c75f3e2cd195f4a01ad2d47
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersefaust
bugs1466000
milestone64.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 1466000 - Part 2: Move call context handling from BytecodeEmitter::emitGetNameAtLocation to BytecodeEmitter::emitCalleeAndThis. r=efaust
js/src/frontend/BytecodeEmitter.cpp
js/src/frontend/BytecodeEmitter.h
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -1709,17 +1709,17 @@ BytecodeEmitter::emitFinishIteratorResul
     }
     if (!emitIndex32(JSOP_INITPROP, done_id)) {
         return false;
     }
     return true;
 }
 
 bool
-BytecodeEmitter::emitGetNameAtLocation(JSAtom* name, const NameLocation& loc, bool callContext)
+BytecodeEmitter::emitGetNameAtLocation(JSAtom* name, const NameLocation& loc)
 {
     switch (loc.kind()) {
       case NameLocation::Kind::Dynamic:
         if (!emitAtomOp(name, JSOP_GETNAME)) {
             return false;
         }
         break;
 
@@ -1774,56 +1774,23 @@ BytecodeEmitter::emitGetNameAtLocation(J
             return false;
         }
         break;
 
       case NameLocation::Kind::DynamicAnnexBVar:
         MOZ_CRASH("Synthesized vars for Annex B.3.3 should only be used in initialization");
     }
 
-    // Need to provide |this| value for call.
-    if (callContext) {
-        switch (loc.kind()) {
-          case NameLocation::Kind::Dynamic: {
-            JSOp thisOp = needsImplicitThis() ? JSOP_IMPLICITTHIS : JSOP_GIMPLICITTHIS;
-            if (!emitAtomOp(name, thisOp)) {
-                return false;
-            }
-            break;
-          }
-
-          case NameLocation::Kind::Global:
-            if (!emitAtomOp(name, JSOP_GIMPLICITTHIS)) {
-                return false;
-            }
-            break;
-
-          case NameLocation::Kind::Intrinsic:
-          case NameLocation::Kind::NamedLambdaCallee:
-          case NameLocation::Kind::Import:
-          case NameLocation::Kind::ArgumentSlot:
-          case NameLocation::Kind::FrameSlot:
-          case NameLocation::Kind::EnvironmentCoordinate:
-            if (!emit1(JSOP_UNDEFINED)) {
-                return false;
-            }
-            break;
-
-          case NameLocation::Kind::DynamicAnnexBVar:
-            MOZ_CRASH("Synthesized vars for Annex B.3.3 should only be used in initialization");
-        }
-    }
-
-    return true;
-}
-
-bool
-BytecodeEmitter::emitGetName(ParseNode* pn, bool callContext)
-{
-    return emitGetName(pn->name(), callContext);
+    return true;
+}
+
+bool
+BytecodeEmitter::emitGetName(ParseNode* pn)
+{
+    return emitGetName(pn->name());
 }
 
 template <typename RHSEmitter>
 bool
 BytecodeEmitter::emitSetOrInitializeNameAtLocation(HandleAtom name, const NameLocation& loc,
                                                    RHSEmitter emitRhs, bool initialize)
 {
     bool emittedBindOp = false;
@@ -7207,21 +7174,57 @@ BytecodeEmitter::isRestParameter(ParseNo
     return false;
 }
 
 bool
 BytecodeEmitter::emitCalleeAndThis(ParseNode* callee, ParseNode* call, bool isCall, bool isNew)
 {
     bool needsThis = !isCall;
     switch (callee->getKind()) {
-      case ParseNodeKind::Name:
-        if (!emitGetName(callee, isCall)) {
-            return false;
-        }
+      case ParseNodeKind::Name: {
+        JSAtom* name = callee->name();
+        NameLocation loc = lookupName(name);
+        if (!emitGetNameAtLocation(name, loc)) {          // CALLEE
+            return false;
+        }
+
+        if (isCall) {
+            switch (loc.kind()) {
+              case NameLocation::Kind::Dynamic: {
+                JSOp thisOp = needsImplicitThis() ? JSOP_IMPLICITTHIS : JSOP_GIMPLICITTHIS;
+                if (!emitAtomOp(name, thisOp)) {
+                    return false;
+                }
+                break;
+              }
+
+              case NameLocation::Kind::Global:
+                if (!emitAtomOp(name, JSOP_GIMPLICITTHIS)) {
+                    return false;
+                }
+                break;
+
+              case NameLocation::Kind::Intrinsic:
+              case NameLocation::Kind::NamedLambdaCallee:
+              case NameLocation::Kind::Import:
+              case NameLocation::Kind::ArgumentSlot:
+              case NameLocation::Kind::FrameSlot:
+              case NameLocation::Kind::EnvironmentCoordinate:
+                if (!emit1(JSOP_UNDEFINED)) {
+                    return false;
+                }
+                break;
+
+              case NameLocation::Kind::DynamicAnnexBVar:
+                MOZ_CRASH("Synthesized vars for Annex B.3.3 should only be used in initialization");
+            }
+        }
+
         break;
+      }
       case ParseNodeKind::Dot: {
         PropertyAccess* prop = &callee->as<PropertyAccess>();
         MOZ_ASSERT(emitterMode != BytecodeEmitter::SelfHosting);
         if (prop->isSuper()) {
             if (!emitSuperGetProp(prop, isCall)) {
                 return false;
             }
         } else {
@@ -7235,23 +7238,27 @@ BytecodeEmitter::emitCalleeAndThis(Parse
       case ParseNodeKind::Elem: {
         PropertyByValue* elem = &callee->as<PropertyByValue>();
         MOZ_ASSERT(emitterMode != BytecodeEmitter::SelfHosting);
         if (elem->isSuper()) {
             if (!emitSuperGetElem(elem, isCall)) {
                 return false;
             }
         } else {
-            if (!emitElemOp(elem, isCall ? JSOP_CALLELEM : JSOP_GETELEM)) {
-                return false;
-            }
             if (isCall) {
+                if (!emitElemOp(elem, JSOP_CALLELEM)) {
+                    return false;
+                }
                 if (!emit1(JSOP_SWAP)) {
                     return false;
                 }
+            } else {
+                if (!emitElemOp(elem, JSOP_GETELEM)) {
+                    return false;
+                }
             }
         }
 
         break;
       }
       case ParseNodeKind::Function:
         /*
          * Top level lambdas which are immediately invoked should be
--- a/js/src/frontend/BytecodeEmitter.h
+++ b/js/src/frontend/BytecodeEmitter.h
@@ -573,24 +573,23 @@ struct MOZ_STACK_CLASS BytecodeEmitter
     // instead be emitted using EmitVarOp. In special cases, when the caller
     // definitely knows that a given local slot is unaliased, this function may be
     // used as a non-asserting version of emitUint16Operand.
     MOZ_MUST_USE bool emitLocalOp(JSOp op, uint32_t slot);
 
     MOZ_MUST_USE bool emitArgOp(JSOp op, uint16_t slot);
     MOZ_MUST_USE bool emitEnvCoordOp(JSOp op, EnvironmentCoordinate ec);
 
-    MOZ_MUST_USE bool emitGetNameAtLocation(JSAtom* name, const NameLocation& loc,
-                                            bool callContext = false);
+    MOZ_MUST_USE bool emitGetNameAtLocation(JSAtom* name, const NameLocation& loc);
     MOZ_MUST_USE bool emitGetNameAtLocationForCompoundAssignment(JSAtom* name,
                                                                  const NameLocation& loc);
-    MOZ_MUST_USE bool emitGetName(JSAtom* name, bool callContext = false) {
-        return emitGetNameAtLocation(name, lookupName(name), callContext);
+    MOZ_MUST_USE bool emitGetName(JSAtom* name) {
+        return emitGetNameAtLocation(name, lookupName(name));
     }
-    MOZ_MUST_USE bool emitGetName(ParseNode* pn, bool callContext = false);
+    MOZ_MUST_USE bool emitGetName(ParseNode* pn);
 
     template <typename RHSEmitter>
     MOZ_MUST_USE bool emitSetOrInitializeNameAtLocation(HandleAtom name, const NameLocation& loc,
                                                         RHSEmitter emitRhs, bool initialize);
     template <typename RHSEmitter>
     MOZ_MUST_USE bool emitSetOrInitializeName(HandleAtom name, RHSEmitter emitRhs,
                                               bool initialize)
     {