From a8745145ea0d69ce86ac8f5ae8ddfbe3bfd1e7a2 Mon Sep 17 00:00:00 2001 From: Eddy Bruel Date: Mon, 6 Jun 2016 14:50:12 +0200 Subject: [PATCH] Bug 1271653 - Implement a C++ interface for name/displayName;r=jimb --- js/src/vm/Debugger.cpp | 73 +++++++++++++++++++++++++++++------------- js/src/vm/Debugger.h | 4 +++ 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/js/src/vm/Debugger.cpp b/js/src/vm/Debugger.cpp index 3e5eeebcdc89..5ab15c41614b 100644 --- a/js/src/vm/Debugger.cpp +++ b/js/src/vm/Debugger.cpp @@ -7906,44 +7906,42 @@ DebuggerObject_getCallable(JSContext* cx, unsigned argc, Value* vp) static bool DebuggerObject_getName(JSContext* cx, unsigned argc, Value* vp) { - THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, "get name", args, dbg, obj); - if (!obj->is()) { + THIS_DEBUGOBJECT(cx, argc, vp, "get name", args, object) + + if (!DebuggerObject::isFunction(cx, object)) { args.rval().setUndefined(); return true; } - JSString* name = obj->as().name(); - if (!name) { - args.rval().setUndefined(); - return true; - } - - RootedValue namev(cx, StringValue(name)); - if (!dbg->wrapDebuggeeValue(cx, &namev)) + RootedString result(cx); + if (!DebuggerObject::name(cx, object, &result)) return false; - args.rval().set(namev); + + if (result) + args.rval().setString(result); + else + args.rval().setUndefined(); return true; } static bool DebuggerObject_getDisplayName(JSContext* cx, unsigned argc, Value* vp) { - THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, "get display name", args, dbg, obj); - if (!obj->is()) { + THIS_DEBUGOBJECT(cx, argc, vp, "get displayName", args, object) + + if (!DebuggerObject::isFunction(cx, object)) { args.rval().setUndefined(); return true; } - JSString* name = obj->as().displayAtom(); - if (!name) { - args.rval().setUndefined(); - return true; - } - - RootedValue namev(cx, StringValue(name)); - if (!dbg->wrapDebuggeeValue(cx, &namev)) + RootedString result(cx); + if (!DebuggerObject::displayName(cx, object, &result)) return false; - args.rval().set(namev); + + if (result) + args.rval().setString(result); + else + args.rval().setUndefined(); return true; } @@ -8844,6 +8842,14 @@ DebuggerObject::create(JSContext* cx, HandleObject proto, HandleObject referent, return &object; } +/* static */ bool +DebuggerObject::isFunction(JSContext* cx, Handle object) +{ + RootedObject referent(cx, object->referent()); + + return referent->is(); +} + /* static */ bool DebuggerObject::className(JSContext* cx, Handle object, MutableHandleString result) @@ -8864,6 +8870,29 @@ DebuggerObject::className(JSContext* cx, Handle object, return true; } +/* static */ bool +DebuggerObject::name(JSContext* cx, Handle object, MutableHandleString result) +{ + MOZ_ASSERT(DebuggerObject::isFunction(cx, object)); + + RootedFunction referent(cx, &object->referent()->as()); + + result.set(referent->name()); + return true; +} + +/* static */ bool +DebuggerObject::displayName(JSContext* cx, Handle object, + MutableHandleString result) +{ + MOZ_ASSERT(DebuggerObject::isFunction(cx, object)); + + RootedFunction referent(cx, &object->referent()->as()); + + result.set(referent->displayAtom()); + return true; +} + /* static */ bool DebuggerObject::isBoundFunction(JSContext* cx, Handle object) { diff --git a/js/src/vm/Debugger.h b/js/src/vm/Debugger.h index 83955d66369b..da6099bd3c54 100644 --- a/js/src/vm/Debugger.h +++ b/js/src/vm/Debugger.h @@ -1051,8 +1051,12 @@ class DebuggerObject : public NativeObject static DebuggerObject* create(JSContext* cx, HandleObject proto, HandleObject obj, HandleNativeObject debugger); + static bool isFunction(JSContext* cx, Handle object); static bool className(JSContext* cx, Handle object, MutableHandleString result); + static bool name(JSContext* cx, Handle object, MutableHandleString result); + static bool displayName(JSContext* cx, Handle object, + MutableHandleString result); static bool isBoundFunction(JSContext* cx, Handle object); static bool boundTargetFunction(JSContext* cx, Handle object, MutableHandleObject result);