Bug 1180290 - Part 1: Add prefix parameter to IdToFunctionName. r=till
authorTooru Fujisawa <arai_a@mac.com>
Tue, 05 Jan 2016 03:21:23 +0900
changeset 278809 b51771070a8993305e2e73a31bc3e82c32de3ae4
parent 278808 f7aa719c43c9639680f4d525b4ad7175e93b459d
child 278810 44725d3301db2d4371e087076aa95801622cf8b2
push id29860
push usercbook@mozilla.com
push dateThu, 07 Jan 2016 10:51:20 +0000
treeherdermozilla-central@e0bcd16e1d4b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstill
bugs1180290
milestone46.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 1180290 - Part 1: Add prefix parameter to IdToFunctionName. r=till
js/src/jsfun.cpp
js/src/jsfun.h
--- a/js/src/jsfun.cpp
+++ b/js/src/jsfun.cpp
@@ -2248,36 +2248,43 @@ js::CloneFunctionAndScript(JSContext* cx
     return clone;
 }
 
 /*
  * 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]".
+ * symbol, this returns "[Symbol.iterator]".  If a prefix is supplied the final
+ * name is |prefix + " " + name|.
  *
- * Implements step 4 of SetFunctionName in ES6 draft rev 27 (24 Aug 2014).
+ * Implements step 4 and 5 of SetFunctionName in ES 2016 draft Dec 20, 2015.
  */
 JSAtom*
-js::IdToFunctionName(JSContext* cx, HandleId id)
+js::IdToFunctionName(JSContext* cx, HandleId id, const char* prefix /* = nullptr */)
 {
-    if (JSID_IS_ATOM(id))
+    if (JSID_IS_ATOM(id) && !prefix)
         return JSID_TO_ATOM(id);
 
-    if (JSID_IS_SYMBOL(id)) {
+    if (JSID_IS_SYMBOL(id) && !prefix) {
         RootedAtom desc(cx, JSID_TO_SYMBOL(id)->description());
         StringBuffer sb(cx);
         if (!sb.append('[') || !sb.append(desc) || !sb.append(']'))
             return nullptr;
         return sb.finishAtom();
     }
 
     RootedValue idv(cx, IdToValue(id));
-    return ToAtom<CanGC>(cx, idv);
+    if (!prefix)
+        return ToAtom<CanGC>(cx, idv);
+
+    StringBuffer sb(cx);
+    if (!sb.append(prefix, strlen(prefix)) || !sb.append(' ') || !sb.append(ToAtom<CanGC>(cx, idv)))
+        return nullptr;
+    return sb.finishAtom();
 }
 
 JSFunction*
 js::DefineFunction(JSContext* cx, HandleObject obj, HandleId id, Native native,
                    unsigned nargs, unsigned flags, AllocKind allocKind /* = AllocKind::FUNCTION */)
 {
     GetterOp gop;
     SetterOp sop;
--- a/js/src/jsfun.h
+++ b/js/src/jsfun.h
@@ -661,17 +661,17 @@ enum NewFunctionProtoHandling {
 extern JSFunction*
 NewFunctionWithProto(ExclusiveContext* cx, JSNative native, unsigned nargs,
                      JSFunction::Flags flags, HandleObject enclosingDynamicScope, HandleAtom atom,
                      HandleObject proto, gc::AllocKind allocKind = gc::AllocKind::FUNCTION,
                      NewObjectKind newKind = GenericObject,
                      NewFunctionProtoHandling protoHandling = NewFunctionClassProto);
 
 extern JSAtom*
-IdToFunctionName(JSContext* cx, HandleId id);
+IdToFunctionName(JSContext* cx, HandleId id, const char* prefix = nullptr);
 
 extern JSFunction*
 DefineFunction(JSContext* cx, HandleObject obj, HandleId id, JSNative native,
                unsigned nargs, unsigned flags,
                gc::AllocKind allocKind = gc::AllocKind::FUNCTION);
 
 bool
 FunctionHasResolveHook(const JSAtomState& atomState, jsid id);