Bug 1300071 - Create an API to access DOM Promise's state. r=bz

MozReview-Commit-ID: LI2Dafkzq5x

--HG--
extra : transplant_source : %DA%0D%EC%0B%8A%AD%80A%CC%17%D2%E6%9F%90%A2%9E%92%1E%26%1A
This commit is contained in:
Kaku Kuo 2016-09-07 10:51:41 +08:00
parent 754426d7c8
commit d619d6d908
2 changed files with 33 additions and 6 deletions

View File

@ -3246,5 +3246,30 @@ Promise::GetID() {
}
#endif // SPIDERMONKEY_PROMISE
#ifndef SPIDERMONKEY_PROMISE
Promise::PromiseState
Promise::State() const
{
return mState;
}
#else // SPIDERMONKEY_PROMISE
Promise::PromiseState
Promise::State() const
{
JS::Rooted<JSObject*> p(RootingCx(), PromiseObj());
const JS::PromiseState state = JS::GetPromiseState(p);
if (state == JS::PromiseState::Fulfilled) {
return PromiseState::Resolved;
}
if (state == JS::PromiseState::Rejected) {
return PromiseState::Rejected;
}
return PromiseState::Pending;
}
#endif // SPIDERMONKEY_PROMISE
} // namespace dom
} // namespace mozilla

View File

@ -313,6 +313,14 @@ public:
JS::Handle<JSObject*> aPromiseObj);
#endif // SPIDERMONKEY_PROMISE
enum class PromiseState {
Pending,
Resolved,
Rejected
};
PromiseState State() const;
protected:
struct PromiseCapability;
@ -369,12 +377,6 @@ protected:
#endif // SPIDERMONKEY_PROMISE
private:
enum PromiseState {
Pending,
Resolved,
Rejected
};
#ifndef SPIDERMONKEY_PROMISE
friend class PromiseDebugging;