Bug 1271653 - Debugger::wrapDebuggeeObject should return a DebuggerObject;r=fitzgen
authorEddy Bruel <ejpbruel@mozilla.com>
Tue, 21 Jun 2016 11:34:34 +0200
changeset 302156 1ee5fb218ea1d28e9ea407c897fe091749d72ab9
parent 302155 7bf21c554c3d7c854bfa7e38e19b3d7315c99b73
child 302161 70cb21780f68346c5f771f73d39056813814fba5
push id78625
push userejpbruel@mozilla.com
push dateTue, 21 Jun 2016 09:34:46 +0000
treeherdermozilla-inbound@1ee5fb218ea1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfitzgen
bugs1271653
milestone50.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 1271653 - Debugger::wrapDebuggeeObject should return a DebuggerObject;r=fitzgen
js/src/vm/Debugger.cpp
js/src/vm/Debugger.h
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -1075,21 +1075,22 @@ Debugger::wrapEnvironment(JSContext* cx,
 
 bool
 Debugger::wrapDebuggeeValue(JSContext* cx, MutableHandleValue vp)
 {
     assertSameCompartment(cx, object.get());
 
     if (vp.isObject()) {
         RootedObject obj(cx, &vp.toObject());
-
-        if (!wrapDebuggeeObject(cx, &obj))
-            return false;
-
-        vp.setObject(*obj);
+        Rooted<DebuggerObject*> dobj(cx);
+
+        if (!wrapDebuggeeObject(cx, obj, &dobj))
+            return false;
+
+        vp.setObject(*dobj);
     } else if (vp.isMagic()) {
         RootedPlainObject optObj(cx, NewBuiltinClassInstance<PlainObject>(cx));
         if (!optObj)
             return false;
 
         // We handle three sentinel values: missing arguments (overloading
         // JS_OPTIMIZED_ARGUMENTS), optimized out slots (JS_OPTIMIZED_OUT),
         // and uninitialized bindings (JS_UNINITIALIZED_LEXICAL).
@@ -1112,35 +1113,36 @@ Debugger::wrapDebuggeeValue(JSContext* c
         vp.setUndefined();
         return false;
     }
 
     return true;
 }
 
 bool
-Debugger::wrapDebuggeeObject(JSContext* cx, MutableHandleObject obj)
+Debugger::wrapDebuggeeObject(JSContext* cx, HandleObject obj,
+                             MutableHandle<DebuggerObject*> result)
 {
     MOZ_ASSERT(obj);
 
     if (obj->is<JSFunction>()) {
         MOZ_ASSERT(!IsInternalFunctionObject(*obj));
         RootedFunction fun(cx, &obj->as<JSFunction>());
         if (!EnsureFunctionHasScript(cx, fun))
             return false;
     }
 
     DependentAddPtr<ObjectWeakMap> p(cx, objects, obj);
     if (p) {
-        obj.set(p->value());
+        result.set(&p->value()->as<DebuggerObject>());
     } else {
         /* Create a new Debugger.Object for obj. */
         RootedNativeObject debugger(cx, object);
         RootedObject proto(cx, &object->getReservedSlot(JSSLOT_DEBUG_OBJECT_PROTO).toObject());
-        NativeObject* dobj = DebuggerObject::create(cx, proto, obj, debugger);
+        Rooted<DebuggerObject*> dobj(cx, DebuggerObject::create(cx, proto, obj, debugger));
         if (!dobj)
             return false;
 
         if (!p.add(cx, objects, obj, dobj)) {
             NukeDebuggerWrapper(dobj);
             return false;
         }
 
@@ -1149,17 +1151,17 @@ Debugger::wrapDebuggeeObject(JSContext* 
             if (!object->compartment()->putWrapper(cx, key, ObjectValue(*dobj))) {
                 NukeDebuggerWrapper(dobj);
                 objects.remove(obj);
                 ReportOutOfMemory(cx);
                 return false;
             }
         }
 
-        obj.set(dobj);
+        result.set(dobj);
     }
 
     return true;
 }
 
 static NativeObject*
 ToNativeDebuggerObject(JSContext* cx, MutableHandleObject obj)
 {
@@ -8884,21 +8886,17 @@ DebuggerObject::className(JSContext* cx,
 /* static */ bool
 DebuggerObject::global(JSContext* cx, Handle<DebuggerObject*> object,
                        MutableHandle<DebuggerObject*> result)
 {
     RootedObject referent(cx, object->referent());
     Debugger* dbg = object->owner();
 
     RootedObject global(cx, &referent->global());
-    if (!dbg->wrapDebuggeeObject(cx, &global))
-        return false;
-
-    result.set(&global->as<DebuggerObject>());
-    return true;
+    return dbg->wrapDebuggeeObject(cx, global, result);
 }
 
 /* static */ bool
 DebuggerObject::name(JSContext* cx, Handle<DebuggerObject*> object, MutableHandleString result)
 {
     MOZ_ASSERT(isFunction(cx, object));
 
     RootedFunction referent(cx, &object->referent()->as<JSFunction>());
@@ -8959,21 +8957,17 @@ DebuggerObject::boundTargetFunction(JSCo
                                     MutableHandle<DebuggerObject*> result)
 {
     MOZ_ASSERT(isBoundFunction(cx, object));
 
     RootedFunction referent(cx, &object->referent()->as<JSFunction>());
     Debugger* dbg = object->owner();
 
     RootedObject target(cx, referent->getBoundFunctionTarget());
-    if (!dbg->wrapDebuggeeObject(cx, &target))
-        return false;
-
-    result.set(&target->as<DebuggerObject>());
-    return true;
+    return dbg->wrapDebuggeeObject(cx, target, result);
 }
 
 /* static */ bool
 DebuggerObject::boundThis(JSContext* cx, Handle<DebuggerObject*> object,
                           MutableHandleValue result)
 {
     MOZ_ASSERT(isBoundFunction(cx, object));
 
@@ -9114,21 +9108,17 @@ DebuggerObject::getPrototypeOf(JSContext
             return false;
     }
 
     if (!proto) {
         result.set(nullptr);
         return true;
     }
 
-    if (!dbg->wrapDebuggeeObject(cx, &proto))
-        return false;
-
-    result.set(&proto->as<DebuggerObject>());
-    return true;
+    return dbg->wrapDebuggeeObject(cx, proto, result);
 }
 
 /* static */ bool
 DebuggerObject::getOwnPropertyNames(JSContext* cx, Handle<DebuggerObject*> object,
                                     MutableHandle<IdVector> result)
 {
     RootedObject referent(cx, object->referent());
 
@@ -9492,21 +9482,17 @@ DebuggerObject::unwrap(JSContext* cx, Ha
     // and the wrapper is in a visible compartment, that's fine.)
     JSCompartment* unwrappedCompartment = unwrapped->compartment();
     if (unwrappedCompartment->creationOptions().invisibleToDebugger()) {
         JS_ReportErrorNumber(cx, GetErrorMessage, nullptr,
                              JSMSG_DEBUG_INVISIBLE_COMPARTMENT);
         return false;
     }
 
-    if (!dbg->wrapDebuggeeObject(cx, &unwrapped))
-        return false;
-
-    result.set(&unwrapped->as<DebuggerObject>());
-    return true;
+    return dbg->wrapDebuggeeObject(cx, unwrapped, result);
 }
 
 /* static */ bool
 DebuggerObject::requireGlobal(JSContext* cx, Handle<DebuggerObject*> object)
 {
     if (!DebuggerObject::isGlobal(cx, object)) {
         RootedObject referent(cx, object->referent());
 
--- a/js/src/vm/Debugger.h
+++ b/js/src/vm/Debugger.h
@@ -240,16 +240,18 @@ typedef JSObject Env;
 //   2. A wasm JSFunction, denoting a synthesized wasm function script.
 //      NYI!
 typedef mozilla::Variant<JSScript*, WasmInstanceObject*> DebuggerScriptReferent;
 
 // Either a ScriptSourceObject, for ordinary JS, or a WasmInstanceObject,
 // denoting the synthesized source of a wasm module.
 typedef mozilla::Variant<ScriptSourceObject*, WasmInstanceObject*> DebuggerSourceReferent;
 
+class DebuggerObject;
+
 class Debugger : private mozilla::LinkedListElement<Debugger>
 {
     friend class Breakpoint;
     friend class DebuggerMemory;
     friend class SavedStacks;
     friend class mozilla::LinkedListElement<Debugger>;
     friend class mozilla::LinkedList<Debugger>;
     friend bool (::JS_DefineDebuggerObject)(JSContext* cx, JS::HandleObject obj);
@@ -923,17 +925,18 @@ class Debugger : private mozilla::Linked
      * arguments, this produces a plain object of the form { missingArguments:
      * true }.
      *
      * If *vp is a magic JS_UNINITIALIZED_LEXICAL value signifying an
      * unaccessible uninitialized binding, this produces a plain object of the
      * form { uninitialized: true }.
      */
     MOZ_MUST_USE bool wrapDebuggeeValue(JSContext* cx, MutableHandleValue vp);
-    MOZ_MUST_USE bool wrapDebuggeeObject(JSContext* cx, MutableHandleObject obj);
+    MOZ_MUST_USE bool wrapDebuggeeObject(JSContext* cx, HandleObject obj,
+                                         MutableHandle<DebuggerObject*> result);
 
     /*
      * Unwrap a Debug.Object, without rewrapping it for any particular debuggee
      * compartment.
      *
      * Preconditions: cx is in the debugger compartment. *vp is a value in that
      * compartment. (*vp should be a "debuggee value", meaning it is the
      * debugger's reflection of a value in the debuggee.)