mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-11 21:58:41 +02:00
Bug 1086627 - Rename Promise constructs to more closely match the specification. r=nsm,jst
--HG-- extra : commitid : 86J3tVySqhI extra : rebase_source : cccb777a893cc44c2edece078e5861aa25f3f52b extra : amend_source : 02c64f4e5ba42d2aa77776826af80927bd231f00
This commit is contained in:
parent
09f58572fa
commit
b44082538c
3 changed files with 30 additions and 31 deletions
|
|
@ -47,10 +47,10 @@ Atomic<uintptr_t> gIDGenerator(0);
|
||||||
using namespace workers;
|
using namespace workers;
|
||||||
|
|
||||||
// This class processes the promise's callbacks with promise's result.
|
// This class processes the promise's callbacks with promise's result.
|
||||||
class PromiseCallbackTask final : public nsRunnable
|
class PromiseReactionJob final : public nsRunnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PromiseCallbackTask(Promise* aPromise,
|
PromiseReactionJob(Promise* aPromise,
|
||||||
PromiseCallback* aCallback,
|
PromiseCallback* aCallback,
|
||||||
const JS::Value& aValue)
|
const JS::Value& aValue)
|
||||||
: mPromise(aPromise)
|
: mPromise(aPromise)
|
||||||
|
|
@ -59,21 +59,21 @@ public:
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(aPromise);
|
MOZ_ASSERT(aPromise);
|
||||||
MOZ_ASSERT(aCallback);
|
MOZ_ASSERT(aCallback);
|
||||||
MOZ_COUNT_CTOR(PromiseCallbackTask);
|
MOZ_COUNT_CTOR(PromiseReactionJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual
|
virtual
|
||||||
~PromiseCallbackTask()
|
~PromiseReactionJob()
|
||||||
{
|
{
|
||||||
NS_ASSERT_OWNINGTHREAD(PromiseCallbackTask);
|
NS_ASSERT_OWNINGTHREAD(PromiseReactionJob);
|
||||||
MOZ_COUNT_DTOR(PromiseCallbackTask);
|
MOZ_COUNT_DTOR(PromiseReactionJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NS_IMETHOD
|
NS_IMETHOD
|
||||||
Run() override
|
Run() override
|
||||||
{
|
{
|
||||||
NS_ASSERT_OWNINGTHREAD(PromiseCallbackTask);
|
NS_ASSERT_OWNINGTHREAD(PromiseReactionJob);
|
||||||
ThreadsafeAutoJSContext cx;
|
ThreadsafeAutoJSContext cx;
|
||||||
JS::Rooted<JSObject*> wrapper(cx, mPromise->GetWrapper());
|
JS::Rooted<JSObject*> wrapper(cx, mPromise->GetWrapper());
|
||||||
MOZ_ASSERT(wrapper); // It was preserved!
|
MOZ_ASSERT(wrapper); // It was preserved!
|
||||||
|
|
@ -822,7 +822,7 @@ Promise::Catch(JSContext* aCx, AnyCallback* aRejectCallback, ErrorResult& aRv)
|
||||||
/**
|
/**
|
||||||
* The CountdownHolder class encapsulates Promise.all countdown functions and
|
* The CountdownHolder class encapsulates Promise.all countdown functions and
|
||||||
* the countdown holder parts of the Promises spec. It maintains the result
|
* the countdown holder parts of the Promises spec. It maintains the result
|
||||||
* array and AllResolveHandlers use SetValue() to set the array indices.
|
* array and AllResolveElementFunctions use SetValue() to set the array indices.
|
||||||
*/
|
*/
|
||||||
class CountdownHolder final : public nsISupports
|
class CountdownHolder final : public nsISupports
|
||||||
{
|
{
|
||||||
|
|
@ -910,17 +910,18 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CountdownHolder)
|
||||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An AllResolveHandler is the per-promise part of the Promise.all() algorithm.
|
* An AllResolveElementFunction is the per-promise
|
||||||
|
* part of the Promise.all() algorithm.
|
||||||
* Every Promise in the handler is handed an instance of this as a resolution
|
* Every Promise in the handler is handed an instance of this as a resolution
|
||||||
* handler and it sets the relevant index in the CountdownHolder.
|
* handler and it sets the relevant index in the CountdownHolder.
|
||||||
*/
|
*/
|
||||||
class AllResolveHandler final : public PromiseNativeHandler
|
class AllResolveElementFunction final : public PromiseNativeHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||||
NS_DECL_CYCLE_COLLECTION_CLASS(AllResolveHandler)
|
NS_DECL_CYCLE_COLLECTION_CLASS(AllResolveElementFunction)
|
||||||
|
|
||||||
AllResolveHandler(CountdownHolder* aHolder, uint32_t aIndex)
|
AllResolveElementFunction(CountdownHolder* aHolder, uint32_t aIndex)
|
||||||
: mCountdownHolder(aHolder), mIndex(aIndex)
|
: mCountdownHolder(aHolder), mIndex(aIndex)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(aHolder);
|
MOZ_ASSERT(aHolder);
|
||||||
|
|
@ -936,11 +937,11 @@ public:
|
||||||
RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override
|
RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override
|
||||||
{
|
{
|
||||||
// Should never be attached to Promise as a reject handler.
|
// Should never be attached to Promise as a reject handler.
|
||||||
MOZ_ASSERT(false, "AllResolveHandler should never be attached to a Promise's reject handler!");
|
MOZ_CRASH("AllResolveElementFunction should never be attached to a Promise's reject handler!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
~AllResolveHandler()
|
~AllResolveElementFunction()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -948,14 +949,14 @@ private:
|
||||||
uint32_t mIndex;
|
uint32_t mIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(AllResolveHandler)
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(AllResolveElementFunction)
|
||||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(AllResolveHandler)
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(AllResolveElementFunction)
|
||||||
|
|
||||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AllResolveHandler)
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AllResolveElementFunction)
|
||||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||||
NS_INTERFACE_MAP_END
|
NS_INTERFACE_MAP_END
|
||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTION(AllResolveHandler, mCountdownHolder)
|
NS_IMPL_CYCLE_COLLECTION(AllResolveElementFunction, mCountdownHolder)
|
||||||
|
|
||||||
/* static */ already_AddRefed<Promise>
|
/* static */ already_AddRefed<Promise>
|
||||||
Promise::All(const GlobalObject& aGlobal,
|
Promise::All(const GlobalObject& aGlobal,
|
||||||
|
|
@ -1019,7 +1020,7 @@ Promise::All(const GlobalObject& aGlobal,
|
||||||
|
|
||||||
for (uint32_t i = 0; i < aPromiseList.Length(); ++i) {
|
for (uint32_t i = 0; i < aPromiseList.Length(); ++i) {
|
||||||
nsRefPtr<PromiseNativeHandler> resolveHandler =
|
nsRefPtr<PromiseNativeHandler> resolveHandler =
|
||||||
new AllResolveHandler(holder, i);
|
new AllResolveElementFunction(holder, i);
|
||||||
|
|
||||||
nsRefPtr<PromiseCallback> resolveCb =
|
nsRefPtr<PromiseCallback> resolveCb =
|
||||||
new NativePromiseCallback(resolveHandler, Resolved);
|
new NativePromiseCallback(resolveHandler, Resolved);
|
||||||
|
|
@ -1132,7 +1133,7 @@ Promise::AppendCallbacks(PromiseCallback* aResolveCallback,
|
||||||
// callbacks with promise's result. If promise's state is rejected, queue a
|
// callbacks with promise's result. If promise's state is rejected, queue a
|
||||||
// task to process our reject callbacks with promise's result.
|
// task to process our reject callbacks with promise's result.
|
||||||
if (mState != Pending) {
|
if (mState != Pending) {
|
||||||
EnqueueCallbackTasks();
|
TriggerPromiseReactions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1387,7 +1388,7 @@ Promise::Settle(JS::Handle<JS::Value> aValue, PromiseState aState)
|
||||||
}
|
}
|
||||||
#endif // defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
#endif // defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
||||||
|
|
||||||
EnqueueCallbackTasks();
|
TriggerPromiseReactions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -1405,7 +1406,7 @@ Promise::MaybeSettle(JS::Handle<JS::Value> aValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Promise::EnqueueCallbackTasks()
|
Promise::TriggerPromiseReactions()
|
||||||
{
|
{
|
||||||
nsTArray<nsRefPtr<PromiseCallback>> callbacks;
|
nsTArray<nsRefPtr<PromiseCallback>> callbacks;
|
||||||
callbacks.SwapElements(mState == Resolved ? mResolveCallbacks
|
callbacks.SwapElements(mState == Resolved ? mResolveCallbacks
|
||||||
|
|
@ -1414,8 +1415,8 @@ Promise::EnqueueCallbackTasks()
|
||||||
mRejectCallbacks.Clear();
|
mRejectCallbacks.Clear();
|
||||||
|
|
||||||
for (uint32_t i = 0; i < callbacks.Length(); ++i) {
|
for (uint32_t i = 0; i < callbacks.Length(); ++i) {
|
||||||
nsRefPtr<PromiseCallbackTask> task =
|
nsRefPtr<PromiseReactionJob> task =
|
||||||
new PromiseCallbackTask(this, callbacks[i], mResult);
|
new PromiseReactionJob(this, callbacks[i], mResult);
|
||||||
DispatchToMicroTask(task);
|
DispatchToMicroTask(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ class Promise : public nsISupports,
|
||||||
public SupportsWeakPtr<Promise>
|
public SupportsWeakPtr<Promise>
|
||||||
{
|
{
|
||||||
friend class NativePromiseCallback;
|
friend class NativePromiseCallback;
|
||||||
friend class PromiseCallbackTask;
|
friend class PromiseReactionJob;
|
||||||
friend class PromiseResolverTask;
|
friend class PromiseResolverTask;
|
||||||
friend class PromiseTask;
|
friend class PromiseTask;
|
||||||
#if defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
#if defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
||||||
|
|
@ -274,8 +274,8 @@ private:
|
||||||
// This method enqueues promise's resolve/reject callbacks with promise's
|
// This method enqueues promise's resolve/reject callbacks with promise's
|
||||||
// result. It's executed when the resolver.resolve() or resolver.reject() is
|
// result. It's executed when the resolver.resolve() or resolver.reject() is
|
||||||
// called or when the promise already has a result and new callbacks are
|
// called or when the promise already has a result and new callbacks are
|
||||||
// appended by then(), catch() or done().
|
// appended by then() or catch().
|
||||||
void EnqueueCallbackTasks();
|
void TriggerPromiseReactions();
|
||||||
|
|
||||||
void Settle(JS::Handle<JS::Value> aValue, Promise::PromiseState aState);
|
void Settle(JS::Handle<JS::Value> aValue, Promise::PromiseState aState);
|
||||||
void MaybeSettle(JS::Handle<JS::Value> aValue, Promise::PromiseState aState);
|
void MaybeSettle(JS::Handle<JS::Value> aValue, Promise::PromiseState aState);
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,6 @@ callback AnyCallback = any (any value);
|
||||||
Exposed=(Window,Worker,System)]
|
Exposed=(Window,Worker,System)]
|
||||||
// Need to escape "Promise" so it's treated as an identifier.
|
// Need to escape "Promise" so it's treated as an identifier.
|
||||||
interface _Promise {
|
interface _Promise {
|
||||||
// TODO bug 875289 - static Promise fulfill(any value);
|
|
||||||
|
|
||||||
// Disable the static methods when the interface object is supposed to be
|
// Disable the static methods when the interface object is supposed to be
|
||||||
// disabled, just in case some code decides to walk over to .constructor from
|
// disabled, just in case some code decides to walk over to .constructor from
|
||||||
// the proto of a promise object or someone screws up and manages to create a
|
// the proto of a promise object or someone screws up and manages to create a
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue