From b44082538cd6acd7093a32161d3d822c901b682e Mon Sep 17 00:00:00 2001 From: "Alpha A." Date: Thu, 6 Aug 2015 17:18:30 +0200 Subject: [PATCH] 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 --- dom/promise/Promise.cpp | 53 ++++++++++++++++++++------------------- dom/promise/Promise.h | 6 ++--- dom/webidl/Promise.webidl | 2 -- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/dom/promise/Promise.cpp b/dom/promise/Promise.cpp index 6d8c68d16d59..73faadc38a02 100644 --- a/dom/promise/Promise.cpp +++ b/dom/promise/Promise.cpp @@ -47,33 +47,33 @@ Atomic 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 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 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::All(const GlobalObject& aGlobal, @@ -1019,7 +1020,7 @@ Promise::All(const GlobalObject& aGlobal, for (uint32_t i = 0; i < aPromiseList.Length(); ++i) { nsRefPtr resolveHandler = - new AllResolveHandler(holder, i); + new AllResolveElementFunction(holder, i); nsRefPtr 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 aValue, PromiseState aState) } #endif // defined(DOM_PROMISE_DEPRECATED_REPORTING) - EnqueueCallbackTasks(); + TriggerPromiseReactions(); } void @@ -1405,7 +1406,7 @@ Promise::MaybeSettle(JS::Handle aValue, } void -Promise::EnqueueCallbackTasks() +Promise::TriggerPromiseReactions() { nsTArray> callbacks; callbacks.SwapElements(mState == Resolved ? mResolveCallbacks @@ -1414,8 +1415,8 @@ Promise::EnqueueCallbackTasks() mRejectCallbacks.Clear(); for (uint32_t i = 0; i < callbacks.Length(); ++i) { - nsRefPtr task = - new PromiseCallbackTask(this, callbacks[i], mResult); + nsRefPtr task = + new PromiseReactionJob(this, callbacks[i], mResult); DispatchToMicroTask(task); } } diff --git a/dom/promise/Promise.h b/dom/promise/Promise.h index f7028a7bdd41..437183c19da5 100644 --- a/dom/promise/Promise.h +++ b/dom/promise/Promise.h @@ -75,7 +75,7 @@ class Promise : public nsISupports, public SupportsWeakPtr { 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 aValue, Promise::PromiseState aState); void MaybeSettle(JS::Handle aValue, Promise::PromiseState aState); diff --git a/dom/webidl/Promise.webidl b/dom/webidl/Promise.webidl index a98bca780c93..69a768e8cbcd 100644 --- a/dom/webidl/Promise.webidl +++ b/dom/webidl/Promise.webidl @@ -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