Bug 911216 - Part 17: Make promise-related Debugger.Object.prototype getters work with wrapped promises. r=shu
authorTill Schneidereit <till@tillschneidereit.net>
Thu, 26 May 2016 16:13:47 +0200
changeset 338191 0a1f4ee953d0e4e8959cb9a75e4b58a6cc3d08df
parent 338190 b55013ae64e5aad4425d8f6dcf21ff8ce3c43375
child 338192 8d3730e7d1f0fb096bfe93d11afd2691e9fe1453
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu
bugs911216
milestone49.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 911216 - Part 17: Make promise-related Debugger.Object.prototype getters work with wrapped promises. r=shu
js/src/jit-test/tests/debug/inspect-wrapped-promise.js
js/src/vm/Debugger.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/debug/inspect-wrapped-promise.js
@@ -0,0 +1,36 @@
+if (typeof Promise === "undefined")
+    quit(0);
+
+let g = newGlobal();
+let dbg = new Debugger();
+let gw = dbg.addDebuggee(g);
+
+g.promise = Promise.resolve(42);
+
+let promiseDO = gw.getOwnPropertyDescriptor('promise').value;
+
+assertEq(promiseDO.isPromise, true);
+
+let state = promiseDO.promiseState;
+assertEq(state.state, "fulfilled");
+assertEq(state.value, 42);
+assertEq("reason" in state, true);
+assertEq(state.reason, undefined);
+
+let allocationSite = promiseDO.promiseAllocationSite;
+// Depending on whether async stacks are activated, this can be null, which
+// has typeof null.
+assertEq(typeof allocationSite === "object", true);
+
+let resolutionSite = promiseDO.promiseResolutionSite;
+// Depending on whether async stacks are activated, this can be null, which
+// has typeof null.
+assertEq(typeof resolutionSite === "object", true);
+
+assertEq(promiseDO.promiseID, 1);
+
+assertEq(typeof promiseDO.promiseDependentPromises, "object");
+assertEq(promiseDO.promiseDependentPromises.length, 0);
+
+assertEq(typeof promiseDO.promiseLifetime, "number");
+assertEq(typeof promiseDO.promiseTimeToResolution, "number");
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -7742,25 +7742,27 @@ DebuggerObject_checkThis(JSContext* cx, 
     if (!obj)                                                                  \
         return false;                                                          \
     Debugger* dbg = Debugger::fromChildJSObject(obj);                          \
     obj = (JSObject*) obj->as<NativeObject>().getPrivate();                    \
     MOZ_ASSERT(obj)
 
 #define THIS_DEBUGOBJECT_PROMISE(cx, argc, vp, fnname, args, obj)                   \
    THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, fnname, args, obj);                      \
+   obj = CheckedUnwrap(obj);                                                        \
    if (!obj->is<PromiseObject>()) {                                                 \
        JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_NOT_EXPECTED_TYPE,  \
                             "Debugger", "Promise", obj->getClass()->name);          \
        return false;                                                                \
    }                                                                                \
    Rooted<PromiseObject*> promise(cx, &obj->as<PromiseObject>());
 
 #define THIS_DEBUGOBJECT_OWNER_PROMISE(cx, argc, vp, fnname, args, dbg, obj)        \
    THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, fnname, args, dbg, obj);           \
+   obj = CheckedUnwrap(obj);                                                        \
    if (!obj->is<PromiseObject>()) {                                                 \
        JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_NOT_EXPECTED_TYPE,  \
                             "Debugger", "Promise", obj->getClass()->name);          \
        return false;                                                                \
    }                                                                                \
    Rooted<PromiseObject*> promise(cx, &obj->as<PromiseObject>());
 
 static bool
@@ -8051,16 +8053,17 @@ null(CallArgs& args)
 }
 
 #ifdef SPIDERMONKEY_PROMISE
 static bool
 DebuggerObject_getIsPromise(JSContext* cx, unsigned argc, Value* vp)
 {
     THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, "get isPromise", args, refobj);
 
+    refobj = CheckedUnwrap(refobj);
     args.rval().setBoolean(refobj->is<PromiseObject>());
     return true;
 }
 
 static bool
 DebuggerObject_getPromiseState(JSContext* cx, unsigned argc, Value* vp)
 {
     THIS_DEBUGOBJECT_OWNER_PROMISE(cx, argc, vp, "get promiseState", args, dbg, refobj);