Bug 911216 - Part 16: Use new Promise inspection Debugger getters to implement legacy functions on PromiseDebugging. r=bz

This commit is contained in:
Till Schneidereit 2016-05-26 16:13:47 +02:00
parent 7486730d33
commit 385d8245b5
3 changed files with 110 additions and 12 deletions

View File

@ -77,6 +77,103 @@ UnwrapPromise(JS::Handle<JSObject*> aPromise, ErrorResult& aRv)
}
return promise;
}
#endif // SPIDERMONKEY_PROMISE
#ifdef SPIDERMONKEY_PROMISE
/* static */ void
PromiseDebugging::GetState(GlobalObject& aGlobal, JS::Handle<JSObject*> aPromise,
PromiseDebuggingStateHolder& aState,
ErrorResult& aRv)
{
JSContext* cx = aGlobal.Context();
JS::Rooted<JSObject*> obj(cx, js::CheckedUnwrap(aPromise));
if (!obj || !JS::IsPromiseObject(obj)) {
aRv.ThrowTypeError<MSG_IS_NOT_PROMISE>(NS_LITERAL_STRING(
"Argument of PromiseDebugging.getState"));
return;
}
switch (JS::GetPromiseState(obj)) {
case JS::PromiseState::Pending:
aState.mState = PromiseDebuggingState::Pending;
break;
case JS::PromiseState::Fulfilled:
aState.mState = PromiseDebuggingState::Fulfilled;
aState.mValue = JS::GetPromiseResult(obj);
break;
case JS::PromiseState::Rejected:
aState.mState = PromiseDebuggingState::Rejected;
aState.mReason = JS::GetPromiseResult(obj);
break;
}
}
/* static */ void
PromiseDebugging::GetPromiseID(GlobalObject& aGlobal,
JS::Handle<JSObject*> aPromise,
nsString& aID,
ErrorResult& aRv)
{
JSContext* cx = aGlobal.Context();
JS::Rooted<JSObject*> obj(cx, js::CheckedUnwrap(aPromise));
if (!obj || !JS::IsPromiseObject(obj)) {
aRv.ThrowTypeError<MSG_IS_NOT_PROMISE>(NS_LITERAL_STRING(
"Argument of PromiseDebugging.getState"));
return;
}
uint64_t promiseID = JS::GetPromiseID(obj);
aID = sIDPrefix;
aID.AppendInt(promiseID);
}
/* static */ void
PromiseDebugging::GetAllocationStack(GlobalObject& aGlobal,
JS::Handle<JSObject*> aPromise,
JS::MutableHandle<JSObject*> aStack,
ErrorResult& aRv)
{
JSContext* cx = aGlobal.Context();
JS::Rooted<JSObject*> obj(cx, js::CheckedUnwrap(aPromise));
if (!obj || !JS::IsPromiseObject(obj)) {
aRv.ThrowTypeError<MSG_IS_NOT_PROMISE>(NS_LITERAL_STRING(
"Argument of PromiseDebugging.getAllocationStack"));
return;
}
aStack.set(JS::GetPromiseAllocationSite(obj));
}
/* static */ void
PromiseDebugging::GetRejectionStack(GlobalObject& aGlobal,
JS::Handle<JSObject*> aPromise,
JS::MutableHandle<JSObject*> aStack,
ErrorResult& aRv)
{
JSContext* cx = aGlobal.Context();
JS::Rooted<JSObject*> obj(cx, js::CheckedUnwrap(aPromise));
if (!obj || !JS::IsPromiseObject(obj)) {
aRv.ThrowTypeError<MSG_IS_NOT_PROMISE>(NS_LITERAL_STRING(
"Argument of PromiseDebugging.getRejectionStack"));
return;
}
aStack.set(JS::GetPromiseResolutionSite(obj));
}
/* static */ void
PromiseDebugging::GetFullfillmentStack(GlobalObject& aGlobal,
JS::Handle<JSObject*> aPromise,
JS::MutableHandle<JSObject*> aStack,
ErrorResult& aRv)
{
JSContext* cx = aGlobal.Context();
JS::Rooted<JSObject*> obj(cx, js::CheckedUnwrap(aPromise));
if (!obj || !JS::IsPromiseObject(obj)) {
aRv.ThrowTypeError<MSG_IS_NOT_PROMISE>(NS_LITERAL_STRING(
"Argument of PromiseDebugging.getFulfillmentStack"));
return;
}
aStack.set(JS::GetPromiseResolutionSite(obj));
}
#else
/* static */ void
PromiseDebugging::GetState(GlobalObject&, JS::Handle<JSObject*> aPromise,

View File

@ -32,11 +32,13 @@ public:
static void Init();
static void Shutdown();
#ifndef SPIDERMONKEY_PROMISE
static void GetState(GlobalObject&, JS::Handle<JSObject*> aPromise,
PromiseDebuggingStateHolder& aState,
ErrorResult& aRv);
static void GetPromiseID(GlobalObject&, JS::Handle<JSObject*>, nsString&,
ErrorResult&);
static void GetAllocationStack(GlobalObject&, JS::Handle<JSObject*> aPromise,
JS::MutableHandle<JSObject*> aStack,
ErrorResult& aRv);
@ -47,6 +49,8 @@ public:
JS::Handle<JSObject*> aPromise,
JS::MutableHandle<JSObject*> aStack,
ErrorResult& aRv);
#ifndef SPIDERMONKEY_PROMISE
static void GetDependentPromises(GlobalObject&,
JS::Handle<JSObject*> aPromise,
nsTArray<RefPtr<Promise>>& aPromises,
@ -56,9 +60,6 @@ public:
ErrorResult& aRv);
static double GetTimeToSettle(GlobalObject&, JS::Handle<JSObject*> aPromise,
ErrorResult& aRv);
static void GetPromiseID(GlobalObject&, JS::Handle<JSObject*>, nsString&,
ErrorResult&);
#endif // SPIDERMONKEY_PROMISE
// Mechanism for watching uncaught instances of Promise.

View File

@ -52,7 +52,6 @@ callback interface UncaughtRejectionObserver {
[ChromeOnly, Exposed=(Window,System)]
interface PromiseDebugging {
#ifndef SPIDERMONKEY_PROMISE
/**
* The various functions on this interface all expect to take promises but
* don't want the WebIDL behavior of assimilating random passed-in objects
@ -68,6 +67,13 @@ interface PromiseDebugging {
[Throws]
static PromiseDebuggingStateHolder getState(object p);
/**
* Return an identifier for a promise. This identifier is guaranteed
* to be unique to the current process.
*/
[Throws]
static DOMString getPromiseID(object p);
/**
* Return the stack to the promise's allocation point. This can
* return null if the promise was not created from script.
@ -91,13 +97,7 @@ interface PromiseDebugging {
[Throws]
static object? getFullfillmentStack(object p);
/**
* Return an identifier for a promise. This identifier is guaranteed
* to be unique to this instance of Firefox.
*/
[Throws]
static DOMString getPromiseID(object p);
#ifndef SPIDERMONKEY_PROMISE
/**
* Get the promises directly depending on a given promise. These are:
*