# HG changeset patch # User Tooru Fujisawa # Date 1451931683 -32400 # Tue Jan 05 03:21:23 2016 +0900 # Node ID c57006f58b390d1d4020e4262cb3aedfc2734b55 # Parent 0771c5eab32f0cee4f7d12bc382298a81e0eabb2 Bug 1180290 - Part 1: Add prefix parameter to IdToFunctionName. diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -2253,31 +2253,48 @@ js::CloneFunctionAndScript(JSContext* cx * property id. * * Function names are always strings. If id is the well-known @@iterator * symbol, this returns "[Symbol.iterator]". * * Implements step 4 of SetFunctionName in ES6 draft rev 27 (24 Aug 2014). */ JSAtom* -js::IdToFunctionName(JSContext* cx, HandleId id) +js::IdToFunctionName(JSContext* cx, HandleId id, const char* prefix) { - if (JSID_IS_ATOM(id)) - return JSID_TO_ATOM(id); + if (JSID_IS_ATOM(id)) { + if (!prefix) + return JSID_TO_ATOM(id); + + StringBuffer sb(cx); + if (!sb.append(prefix, strlen(prefix)) || !sb.append(' ') || !sb.append(JSID_TO_ATOM(id))) + return nullptr; + return sb.finishAtom(); + } if (JSID_IS_SYMBOL(id)) { RootedAtom desc(cx, JSID_TO_SYMBOL(id)->description()); StringBuffer sb(cx); + if (prefix) { + if (!sb.append(prefix, strlen(prefix)) || !sb.append(' ')) + return nullptr; + } if (!sb.append('[') || !sb.append(desc) || !sb.append(']')) return nullptr; return sb.finishAtom(); } RootedValue idv(cx, IdToValue(id)); - return ToAtom(cx, idv); + if (!prefix) + return ToAtom(cx, idv); + + StringBuffer sb(cx); + if (!sb.append(prefix, strlen(prefix)) || !sb.append(' ') || !sb.append(ToAtom(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; diff --git a/js/src/jsfun.h b/js/src/jsfun.h --- a/js/src/jsfun.h +++ b/js/src/jsfun.h @@ -659,17 +659,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);