Bug 1189644 - Update waitUntil() and activation to spec. r=catalinb
☠☠ backed out by ac055dab935a ☠ ☠
authorNikhil Marathe <nsm.nikhil@gmail.com>
Fri, 21 Aug 2015 16:13:54 -0700
changeset 259075 471a45b97ce2264a08a933bdddcf8c71f65b001a
parent 259074 4d96f2d4807728039747d701d766b67108d96968
child 259076 a7c27770b861504e13e95d4d58998eb50c634884
push id64130
push usernsm.nikhil@gmail.com
push dateMon, 24 Aug 2015 20:03:39 +0000
treeherdermozilla-inbound@d4fa5cfc4b86 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscatalinb
bugs1189644
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1189644 - Update waitUntil() and activation to spec. r=catalinb waitUntil() has been updated to accept multiple calls and concatenate them into Promise.all(). activation does not fail any more even if the promise(s) passed to waitUntil() reject. Update web-platform-tests expected data
dom/workers/ServiceWorkerEvents.cpp
dom/workers/ServiceWorkerEvents.h
dom/workers/ServiceWorkerManager.cpp
testing/web-platform/mozilla/meta/service-workers/service-worker/extendable-event-waituntil.https.html.ini
--- a/dom/workers/ServiceWorkerEvents.cpp
+++ b/dom/workers/ServiceWorkerEvents.cpp
@@ -399,29 +399,44 @@ ExtendableEvent::WaitUntil(Promise& aPro
 {
   MOZ_ASSERT(!NS_IsMainThread());
 
   if (EventPhase() == nsIDOMEvent::NONE) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
 
-  // Only first caller counts.
-  if (EventPhase() == AT_TARGET && !mPromise) {
-    mPromise = &aPromise;
+  mPromises.AppendElement(&aPromise);
+}
+
+already_AddRefed<Promise>
+ExtendableEvent::GetPromise()
+{
+  WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
+  MOZ_ASSERT(worker);
+  worker->AssertIsOnWorkerThread();
+
+  GlobalObject global(worker->GetJSContext(), worker->GlobalScope()->GetGlobalJSObject());
+
+  ErrorResult result;
+  nsRefPtr<Promise> p = Promise::All(global, Move(mPromises), result);
+  if (NS_WARN_IF(result.Failed())) {
+    return nullptr;
   }
+
+  return p.forget();
 }
 
 NS_IMPL_ADDREF_INHERITED(ExtendableEvent, Event)
 NS_IMPL_RELEASE_INHERITED(ExtendableEvent, Event)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ExtendableEvent)
 NS_INTERFACE_MAP_END_INHERITING(Event)
 
-NS_IMPL_CYCLE_COLLECTION_INHERITED(ExtendableEvent, Event, mPromise)
+NS_IMPL_CYCLE_COLLECTION_INHERITED(ExtendableEvent, Event, mPromises)
 
 #ifndef MOZ_SIMPLEPUSH
 
 PushMessageData::PushMessageData(const nsAString& aData)
   : mData(aData)
 {
 }
 
--- a/dom/workers/ServiceWorkerEvents.h
+++ b/dom/workers/ServiceWorkerEvents.h
@@ -97,17 +97,17 @@ public:
   ForwardTo(const nsAString& aUrl);
 
   already_AddRefed<Promise>
   Default();
 };
 
 class ExtendableEvent : public Event
 {
-  nsRefPtr<Promise> mPromise;
+  nsTArray<nsRefPtr<Promise>> mPromises;
 
 protected:
   explicit ExtendableEvent(mozilla::dom::EventTarget* aOwner);
   ~ExtendableEvent() {}
 
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ExtendableEvent, Event)
@@ -139,21 +139,17 @@ public:
     nsCOMPtr<EventTarget> target = do_QueryInterface(aGlobal.GetAsSupports());
     return Constructor(target, aType, aOptions);
   }
 
   void
   WaitUntil(Promise& aPromise, ErrorResult& aRv);
 
   already_AddRefed<Promise>
-  GetPromise() const
-  {
-    nsRefPtr<Promise> p = mPromise;
-    return p.forget();
-  }
+  GetPromise();
 
   virtual ExtendableEvent* AsExtendableEvent() override
   {
     return this;
   }
 };
 
 #ifndef MOZ_SIMPLEPUSH
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -2975,24 +2975,20 @@ ServiceWorkerManager::HandleError(JSCont
 
 void
 ServiceWorkerRegistrationInfo::FinishActivate(bool aSuccess)
 {
   if (mPendingUninstall || !mActiveWorker) {
     return;
   }
 
-  if (aSuccess) {
-    mActiveWorker->UpdateState(ServiceWorkerState::Activated);
-    nsRefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
-    swm->StoreRegistration(mPrincipal, this);
-  } else {
-    mActiveWorker->UpdateState(ServiceWorkerState::Redundant);
-    mActiveWorker = nullptr;
-  }
+  // Activation never fails, so aSuccess is ignored.
+  mActiveWorker->UpdateState(ServiceWorkerState::Activated);
+  nsRefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
+  swm->StoreRegistration(mPrincipal, this);
 }
 
 NS_IMETHODIMP
 ServiceWorkerManager::CreateServiceWorkerForWindow(nsPIDOMWindow* aWindow,
                                                    ServiceWorkerInfo* aInfo,
                                                    nsIRunnable* aLoadFailedRunnable,
                                                    ServiceWorker** aServiceWorker)
 {
deleted file mode 100644
--- a/testing/web-platform/mozilla/meta/service-workers/service-worker/extendable-event-waituntil.https.html.ini
+++ /dev/null
@@ -1,9 +0,0 @@
-[extendable-event-waituntil.https.html]
-  type: testharness
-  expected: TIMEOUT
-  [Test ExtendableEvent waitUntil reject precedence.]
-    expected: TIMEOUT
-
-  [Test activate event waitUntil rejected.]
-    expected: TIMEOUT
-