From 8de72f868e0ba4bb7f70c79360449f7af80fe4ca Mon Sep 17 00:00:00 2001 From: Eddy Bruel Date: Mon, 6 Jun 2016 14:49:24 +0200 Subject: [PATCH] Bug 1271653 - Implement a C++ interface for proto and className;r=jimb --- js/src/vm/Debugger.cpp | 71 +++++++++++++++++++++++++++++++----------- js/src/vm/Debugger.h | 4 +++ 2 files changed, 56 insertions(+), 19 deletions(-) diff --git a/js/src/vm/Debugger.cpp b/js/src/vm/Debugger.cpp index f520014d3814..3e5eeebcdc89 100644 --- a/js/src/vm/Debugger.cpp +++ b/js/src/vm/Debugger.cpp @@ -1118,6 +1118,8 @@ Debugger::wrapDebuggeeValue(JSContext* cx, MutableHandleValue vp) bool Debugger::wrapDebuggeeObject(JSContext* cx, MutableHandleObject obj) { + MOZ_ASSERT(obj); + if (obj->is()) { MOZ_ASSERT(!IsInternalFunctionObject(*obj)); RootedFunction fun(cx, &obj->as()); @@ -7870,33 +7872,26 @@ DebuggerObject_construct(JSContext* cx, unsigned argc, Value* vp) static bool DebuggerObject_getProto(JSContext* cx, unsigned argc, Value* vp) { - THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, "get proto", args, dbg, refobj); - RootedObject proto(cx); - { - AutoCompartment ac(cx, refobj); - if (!GetPrototype(cx, refobj, &proto)) - return false; - } - RootedValue protov(cx, ObjectOrNullValue(proto)); - if (!dbg->wrapDebuggeeValue(cx, &protov)) + THIS_DEBUGOBJECT(cx, argc, vp, "get proto", args, object) + + RootedObject result(cx); + if (!DebuggerObject::getPrototypeOf(cx, object, &result)) return false; - args.rval().set(protov); + + args.rval().setObjectOrNull(result); return true; } static bool DebuggerObject_getClass(JSContext* cx, unsigned argc, Value* vp) { - THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, "get class", args, refobj); - const char* className; - { - AutoCompartment ac(cx, refobj); - className = GetObjectClassName(cx, refobj); - } - JSAtom* str = Atomize(cx, className, strlen(className)); - if (!str) + THIS_DEBUGOBJECT(cx, argc, vp, "get class", args, object) + + RootedString result(cx); + if (!DebuggerObject::className(cx, object, &result)) return false; - args.rval().setString(str); + + args.rval().setString(result); return true; } @@ -8849,6 +8844,26 @@ DebuggerObject::create(JSContext* cx, HandleObject proto, HandleObject referent, return &object; } +/* static */ bool +DebuggerObject::className(JSContext* cx, Handle object, + MutableHandleString result) +{ + RootedObject referent(cx, object->referent()); + + const char* className; + { + AutoCompartment ac(cx, referent); + className = GetObjectClassName(cx, referent); + } + + JSAtom* str = Atomize(cx, className, strlen(className)); + if (!str) + return false; + + result.set(str); + return true; +} + /* static */ bool DebuggerObject::isBoundFunction(JSContext* cx, Handle object) { @@ -8939,6 +8954,24 @@ DebuggerObject::isFrozen(JSContext* cx, Handle object, bool& re return TestIntegrityLevel(cx, referent, IntegrityLevel::Frozen, &result); } +/* static */ bool +DebuggerObject::getPrototypeOf(JSContext* cx, Handle object, + MutableHandleObject result) +{ + RootedObject referent(cx, object->referent()); + Debugger* dbg = object->owner(); + + RootedObject proto(cx); + { + AutoCompartment ac(cx, referent); + if (!GetPrototype(cx, referent, &proto)) + return false; + } + + result.set(proto); + return !result || dbg->wrapDebuggeeObject(cx, result); +} + /* static */ bool DebuggerObject::getOwnPropertyNames(JSContext* cx, Handle object, MutableHandle result) diff --git a/js/src/vm/Debugger.h b/js/src/vm/Debugger.h index 1ff9686f865f..83955d66369b 100644 --- a/js/src/vm/Debugger.h +++ b/js/src/vm/Debugger.h @@ -1051,6 +1051,8 @@ class DebuggerObject : public NativeObject static DebuggerObject* create(JSContext* cx, HandleObject proto, HandleObject obj, HandleNativeObject debugger); + static bool className(JSContext* cx, Handle object, + MutableHandleString result); static bool isBoundFunction(JSContext* cx, Handle object); static bool boundTargetFunction(JSContext* cx, Handle object, MutableHandleObject result); @@ -1062,6 +1064,8 @@ class DebuggerObject : public NativeObject static bool isExtensible(JSContext* cx, Handle object, bool& result); static bool isSealed(JSContext* cx, Handle object, bool& result); static bool isFrozen(JSContext* cx, Handle object, bool& result); + static bool getPrototypeOf(JSContext* cx, Handle object, + MutableHandleObject result); static bool getOwnPropertyNames(JSContext* cx, Handle object, MutableHandle result); static bool getOwnPropertySymbols(JSContext* cx, Handle object,