summaryrefslogtreecommitdiff
path: root/js/src/vm/SelfHosting.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/vm/SelfHosting.cpp')
-rw-r--r--js/src/vm/SelfHosting.cpp38
1 files changed, 15 insertions, 23 deletions
diff --git a/js/src/vm/SelfHosting.cpp b/js/src/vm/SelfHosting.cpp
index 38785a822c..29c75c2064 100644
--- a/js/src/vm/SelfHosting.cpp
+++ b/js/src/vm/SelfHosting.cpp
@@ -571,39 +571,31 @@ intrinsic_FinishBoundFunctionInit(JSContext* cx, unsigned argc, Value* vp)
bound->setExtendedSlot(BOUND_FUN_LENGTH_SLOT, NumberValue(length));
// Try to avoid invoking the resolve hook.
- JSAtom* name = nullptr;
- if (targetObj->is<JSFunction>() && !targetObj->as<JSFunction>().hasResolvedName())
- name = targetObj->as<JSFunction>().getUnresolvedName(cx);
+ RootedAtom name(cx);
+ if (targetObj->is<JSFunction>() && !targetObj->as<JSFunction>().hasResolvedName()) {
+ if (!JSFunction::getUnresolvedName(cx, targetObj.as<JSFunction>(), &name))
+ return false;
+ }
- RootedString rootedName(cx);
- if (name) {
- rootedName = name;
- } else {
+ // 19.2.3.2 Function.prototype.bind, steps 9-11.
+ if (!name) {
// 19.2.3.2 Function.prototype.bind, step 9.
RootedValue targetName(cx);
if (!GetProperty(cx, targetObj, targetObj, cx->names().name, &targetName))
return false;
// 19.2.3.2 Function.prototype.bind, step 10.
- if (targetName.isString())
- rootedName = targetName.toString();
+ if (targetName.isString() && !targetName.toString()->empty()) {
+ name = AtomizeString(cx, targetName.toString());
+ if (!name)
+ return false;
+ } else {
+ name = cx->names().empty;
+ }
}
- // 19.2.3.2 Function.prototype.bind, step 11 (Inlined SetFunctionName).
MOZ_ASSERT(!bound->hasGuessedAtom());
- if (rootedName && !rootedName->empty()) {
- StringBuffer sb(cx);
- if (!sb.append(cx->names().boundWithSpace) || !sb.append(rootedName))
- return false;
-
- RootedAtom nameAtom(cx, sb.finishAtom());
- if (!nameAtom)
- return false;
-
- bound->setAtom(nameAtom);
- } else {
- bound->setAtom(cx->names().boundWithSpace);
- }
+ bound->setAtom(name);
args.rval().setUndefined();
return true;