Bug 1448837: Remove code to handle already set name now that parse nodes can no longer be emitted twice. r=arai
authorAndré Bargull <andre.bargull@gmail.com>
Wed, 28 Mar 2018 05:45:21 -0700
changeset 410474 4cd76f6e6217f67a679a66facf705f2670f679d1
parent 410473 5d0273aecd2995e0033227b660fc87937bd77b34
child 410475 480ce1d9da6159328623004416eeeb486039d88e
push id33729
push userrgurzau@mozilla.com
push dateWed, 28 Mar 2018 21:55:49 +0000
treeherdermozilla-central@6aa3b57955fe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1448837
milestone61.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 1448837: Remove code to handle already set name now that parse nodes can no longer be emitted twice. r=arai
js/src/frontend/BytecodeEmitter.cpp
js/src/vm/JSFunction.cpp
js/src/vm/JSFunction.h
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -5484,30 +5484,17 @@ BytecodeEmitter::setOrEmitSetFunName(Par
                                      FunctionPrefixKind prefixKind)
 {
     MOZ_ASSERT(maybeFun->isDirectRHSAnonFunction());
 
     if (maybeFun->isKind(ParseNodeKind::Function)) {
         // Function doesn't have 'name' property at this point.
         // Set function's name at compile time.
         JSFunction* fun = maybeFun->pn_funbox->function();
-
-        // Single node can be emitted multiple times if it appears in
-        // array destructuring default.  If function already has a name,
-        // just return.
-        if (fun->hasInferredName()) {
-#ifdef DEBUG
-            RootedFunction rootedFun(cx, fun);
-            JSAtom* funName = NameToFunctionName(cx, name, prefixKind);
-            if (!funName)
-                return false;
-            MOZ_ASSERT(funName == rootedFun->inferredName());
-#endif
-            return true;
-        }
+        MOZ_ASSERT(!fun->hasInferredName());
 
         fun->setInferredName(name);
         return true;
     }
 
     MOZ_ASSERT(maybeFun->isKind(ParseNodeKind::Class));
 
     uint32_t nameIndex;
--- a/js/src/vm/JSFunction.cpp
+++ b/js/src/vm/JSFunction.cpp
@@ -2326,67 +2326,70 @@ SymbolToFunctionName(JSContext* cx, JS::
     if (desc) {
         // Step 4.c.
         if (!sb.append('[') || !sb.append(desc) || !sb.append(']'))
             return nullptr;
     }
     return sb.finishAtom();
 }
 
+static JSAtom*
+NameToFunctionName(JSContext* cx, HandleValue name, FunctionPrefixKind prefixKind)
+{
+    MOZ_ASSERT(name.isString() || name.isNumber());
+
+    if (prefixKind == FunctionPrefixKind::None)
+        return ToAtom<CanGC>(cx, name);
+
+    JSString* nameStr = ToString(cx, name);
+    if (!nameStr)
+        return nullptr;
+
+    StringBuffer sb(cx);
+    if (prefixKind == FunctionPrefixKind::Get) {
+        if (!sb.append("get "))
+            return nullptr;
+    } else {
+        if (!sb.append("set "))
+            return nullptr;
+    }
+    if (!sb.append(nameStr))
+        return nullptr;
+    return sb.finishAtom();
+}
+
 /*
  * Return an atom for use as the name of a builtin method with the given
  * property id.
  *
  * Function names are always strings. If id is the well-known @@iterator
  * symbol, this returns "[Symbol.iterator]".  If a prefix is supplied the final
  * name is |prefix + " " + name|.
  *
  * Implements steps 3-5 of 9.2.11 SetFunctionName in ES2016.
  */
 JSAtom*
 js::IdToFunctionName(JSContext* cx, HandleId id,
                      FunctionPrefixKind prefixKind /* = FunctionPrefixKind::None */)
 {
+    MOZ_ASSERT(JSID_IS_STRING(id) || JSID_IS_SYMBOL(id) || JSID_IS_INT(id));
+
     // No prefix fastpath.
     if (JSID_IS_ATOM(id) && prefixKind == FunctionPrefixKind::None)
         return JSID_TO_ATOM(id);
 
     // Step 3 (implicit).
 
     // Step 4.
     if (JSID_IS_SYMBOL(id))
         return SymbolToFunctionName(cx, JSID_TO_SYMBOL(id), prefixKind);
 
+    // Step 5.
     RootedValue idv(cx, IdToValue(id));
-    RootedAtom name(cx, ToAtom<CanGC>(cx, idv));
-    if (!name)
-        return nullptr;
-
-    // Step 5.
-    return NameToFunctionName(cx, name, prefixKind);
-}
-
-JSAtom*
-js::NameToFunctionName(JSContext* cx, HandleAtom name,
-                       FunctionPrefixKind prefixKind /* = FunctionPrefixKind::None */)
-{
-    if (prefixKind == FunctionPrefixKind::None)
-        return name;
-
-    StringBuffer sb(cx);
-    if (prefixKind == FunctionPrefixKind::Get) {
-        if (!sb.append("get "))
-            return nullptr;
-    } else {
-        if (!sb.append("set "))
-            return nullptr;
-    }
-    if (!sb.append(name))
-        return nullptr;
-    return sb.finishAtom();
+    return NameToFunctionName(cx, idv, prefixKind);
 }
 
 bool
 js::SetFunctionNameIfNoOwnName(JSContext* cx, HandleFunction fun, HandleValue name,
                                FunctionPrefixKind prefixKind)
 {
     MOZ_ASSERT(name.isString() || name.isSymbol() || name.isNumber());
 
@@ -2402,36 +2405,30 @@ js::SetFunctionNameIfNoOwnName(JSContext
         // A class may have static 'name' method or accessor.
         if (fun->contains(cx, cx->names().name))
             return true;
     } else {
         // Anonymous function shouldn't have own 'name' property at this point.
         MOZ_ASSERT(!fun->containsPure(cx->names().name));
     }
 
-    JSAtom* funNameAtom;
-    if (name.isSymbol()) {
-        funNameAtom = SymbolToFunctionName(cx, name.toSymbol(), prefixKind);
-    } else {
-        RootedAtom nameAtom(cx, ToAtom<CanGC>(cx, name));
-        if (!nameAtom)
-            return false;
-        funNameAtom = NameToFunctionName(cx, nameAtom, prefixKind);
-    }
-    if (!funNameAtom)
+    JSAtom* funName = name.isSymbol()
+                      ? SymbolToFunctionName(cx, name.toSymbol(), prefixKind)
+                      : NameToFunctionName(cx, name, prefixKind);
+    if (!funName)
         return false;
 
     // RESOLVED_NAME shouldn't yet be set, at least as long as we don't
     // support the "static public fields" or "decorators" proposal.
     // These two proposals allow to access class constructors before
     // JSOP_SETFUNNAME is executed, which means user code may have set the
     // RESOLVED_NAME flag when we reach this point.
     MOZ_ASSERT(!fun->hasResolvedName());
 
-    fun->setInferredName(funNameAtom);
+    fun->setInferredName(funName);
 
     return true;
 }
 
 JSFunction*
 js::DefineFunction(JSContext* cx, HandleObject obj, HandleId id, Native native,
                    unsigned nargs, unsigned flags, AllocKind allocKind /* = AllocKind::FUNCTION */)
 {
--- a/js/src/vm/JSFunction.h
+++ b/js/src/vm/JSFunction.h
@@ -836,20 +836,16 @@ NewScriptedFunction(JSContext* cx, unsig
                     HandleAtom atom, HandleObject proto = nullptr,
                     gc::AllocKind allocKind = gc::AllocKind::FUNCTION,
                     NewObjectKind newKind = GenericObject,
                     HandleObject enclosingEnv = nullptr);
 extern JSAtom*
 IdToFunctionName(JSContext* cx, HandleId id,
                  FunctionPrefixKind prefixKind = FunctionPrefixKind::None);
 
-extern JSAtom*
-NameToFunctionName(JSContext* cx, HandleAtom name,
-                   FunctionPrefixKind prefixKind = FunctionPrefixKind::None);
-
 extern bool
 SetFunctionNameIfNoOwnName(JSContext* cx, HandleFunction fun, HandleValue name,
                            FunctionPrefixKind prefixKind);
 
 extern JSFunction*
 DefineFunction(JSContext* cx, HandleObject obj, HandleId id, JSNative native,
                unsigned nargs, unsigned flags,
                gc::AllocKind allocKind = gc::AllocKind::FUNCTION);