mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1086627 - Rename Promise constructs to more closely match the specification. r=nsm,jst
This commit is contained in:
parent
2b09672a62
commit
d2c0fcc803
@ -47,33 +47,33 @@ Atomic<uintptr_t> gIDGenerator(0);
|
||||
using namespace workers;
|
||||
|
||||
// This class processes the promise's callbacks with promise's result.
|
||||
class PromiseCallbackTask final : public nsRunnable
|
||||
class PromiseReactionJob final : public nsRunnable
|
||||
{
|
||||
public:
|
||||
PromiseCallbackTask(Promise* aPromise,
|
||||
PromiseCallback* aCallback,
|
||||
const JS::Value& aValue)
|
||||
PromiseReactionJob(Promise* aPromise,
|
||||
PromiseCallback* aCallback,
|
||||
const JS::Value& aValue)
|
||||
: mPromise(aPromise)
|
||||
, mCallback(aCallback)
|
||||
, mValue(CycleCollectedJSRuntime::Get()->Runtime(), aValue)
|
||||
{
|
||||
MOZ_ASSERT(aPromise);
|
||||
MOZ_ASSERT(aCallback);
|
||||
MOZ_COUNT_CTOR(PromiseCallbackTask);
|
||||
MOZ_COUNT_CTOR(PromiseReactionJob);
|
||||
}
|
||||
|
||||
virtual
|
||||
~PromiseCallbackTask()
|
||||
~PromiseReactionJob()
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(PromiseCallbackTask);
|
||||
MOZ_COUNT_DTOR(PromiseCallbackTask);
|
||||
NS_ASSERT_OWNINGTHREAD(PromiseReactionJob);
|
||||
MOZ_COUNT_DTOR(PromiseReactionJob);
|
||||
}
|
||||
|
||||
protected:
|
||||
NS_IMETHOD
|
||||
Run() override
|
||||
{
|
||||
NS_ASSERT_OWNINGTHREAD(PromiseCallbackTask);
|
||||
NS_ASSERT_OWNINGTHREAD(PromiseReactionJob);
|
||||
ThreadsafeAutoJSContext cx;
|
||||
JS::Rooted<JSObject*> wrapper(cx, mPromise->GetWrapper());
|
||||
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 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
|
||||
{
|
||||
@ -910,17 +910,18 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CountdownHolder)
|
||||
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
|
||||
* handler and it sets the relevant index in the CountdownHolder.
|
||||
*/
|
||||
class AllResolveHandler final : public PromiseNativeHandler
|
||||
class AllResolveElementFunction final : public PromiseNativeHandler
|
||||
{
|
||||
public:
|
||||
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)
|
||||
{
|
||||
MOZ_ASSERT(aHolder);
|
||||
@ -936,11 +937,11 @@ public:
|
||||
RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override
|
||||
{
|
||||
// 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:
|
||||
~AllResolveHandler()
|
||||
~AllResolveElementFunction()
|
||||
{
|
||||
}
|
||||
|
||||
@ -948,14 +949,14 @@ private:
|
||||
uint32_t mIndex;
|
||||
};
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(AllResolveHandler)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(AllResolveHandler)
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(AllResolveElementFunction)
|
||||
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_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION(AllResolveHandler, mCountdownHolder)
|
||||
NS_IMPL_CYCLE_COLLECTION(AllResolveElementFunction, mCountdownHolder)
|
||||
|
||||
/* static */ already_AddRefed<Promise>
|
||||
Promise::All(const GlobalObject& aGlobal,
|
||||
@ -1019,7 +1020,7 @@ Promise::All(const GlobalObject& aGlobal,
|
||||
|
||||
for (uint32_t i = 0; i < aPromiseList.Length(); ++i) {
|
||||
nsRefPtr<PromiseNativeHandler> resolveHandler =
|
||||
new AllResolveHandler(holder, i);
|
||||
new AllResolveElementFunction(holder, i);
|
||||
|
||||
nsRefPtr<PromiseCallback> resolveCb =
|
||||
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
|
||||
// task to process our reject callbacks with promise's result.
|
||||
if (mState != Pending) {
|
||||
EnqueueCallbackTasks();
|
||||
TriggerPromiseReactions();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1387,7 +1388,7 @@ Promise::Settle(JS::Handle<JS::Value> aValue, PromiseState aState)
|
||||
}
|
||||
#endif // defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
||||
|
||||
EnqueueCallbackTasks();
|
||||
TriggerPromiseReactions();
|
||||
}
|
||||
|
||||
void
|
||||
@ -1405,7 +1406,7 @@ Promise::MaybeSettle(JS::Handle<JS::Value> aValue,
|
||||
}
|
||||
|
||||
void
|
||||
Promise::EnqueueCallbackTasks()
|
||||
Promise::TriggerPromiseReactions()
|
||||
{
|
||||
nsTArray<nsRefPtr<PromiseCallback>> callbacks;
|
||||
callbacks.SwapElements(mState == Resolved ? mResolveCallbacks
|
||||
@ -1414,8 +1415,8 @@ Promise::EnqueueCallbackTasks()
|
||||
mRejectCallbacks.Clear();
|
||||
|
||||
for (uint32_t i = 0; i < callbacks.Length(); ++i) {
|
||||
nsRefPtr<PromiseCallbackTask> task =
|
||||
new PromiseCallbackTask(this, callbacks[i], mResult);
|
||||
nsRefPtr<PromiseReactionJob> task =
|
||||
new PromiseReactionJob(this, callbacks[i], mResult);
|
||||
DispatchToMicroTask(task);
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ class Promise : public nsISupports,
|
||||
public SupportsWeakPtr<Promise>
|
||||
{
|
||||
friend class NativePromiseCallback;
|
||||
friend class PromiseCallbackTask;
|
||||
friend class PromiseReactionJob;
|
||||
friend class PromiseResolverTask;
|
||||
friend class PromiseTask;
|
||||
#if defined(DOM_PROMISE_DEPRECATED_REPORTING)
|
||||
@ -274,8 +274,8 @@ private:
|
||||
// This method enqueues promise's resolve/reject callbacks with promise's
|
||||
// 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
|
||||
// appended by then(), catch() or done().
|
||||
void EnqueueCallbackTasks();
|
||||
// appended by then() or catch().
|
||||
void TriggerPromiseReactions();
|
||||
|
||||
void Settle(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)]
|
||||
// Need to escape "Promise" so it's treated as an identifier.
|
||||
interface _Promise {
|
||||
// TODO bug 875289 - static Promise fulfill(any value);
|
||||
|
||||
// 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
|
||||
// the proto of a promise object or someone screws up and manages to create a
|
||||
|
Loading…
Reference in New Issue
Block a user