diff --git a/dom/workers/ServiceWorker.cpp b/dom/workers/ServiceWorker.cpp index 46129c6c3d2..45b915e3cbd 100644 --- a/dom/workers/ServiceWorker.cpp +++ b/dom/workers/ServiceWorker.cpp @@ -90,17 +90,22 @@ ServiceWorker::PostMessage(JSContext* aCx, JS::Handle aMessage, const Optional>& aTransferable, ErrorResult& aRv) { - WorkerPrivate* workerPrivate = GetWorkerPrivate(); - MOZ_ASSERT(workerPrivate); - if (State() == ServiceWorkerState::Redundant) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } nsCOMPtr window = do_QueryInterface(GetParentObject()); - nsCOMPtr doc = window->GetExtantDoc(); - nsAutoPtr clientInfo(new ServiceWorkerClientInfo(doc)); + if (!window || !window->GetExtantDoc()) { + NS_WARNING("Trying to call post message from an invalid dom object."); + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); + return; + } + + WorkerPrivate* workerPrivate = GetWorkerPrivate(); + MOZ_ASSERT(workerPrivate); + + nsAutoPtr clientInfo(new ServiceWorkerClientInfo(window->GetExtantDoc())); workerPrivate->PostMessageToServiceWorker(aCx, aMessage, aTransferable, clientInfo, aRv); diff --git a/testing/web-platform/mozilla/meta/service-workers/service-worker/fetch-event-async-respond-with.https.html.ini b/testing/web-platform/mozilla/meta/service-workers/service-worker/fetch-event-async-respond-with.https.html.ini index f44bb2122de..dcee8d7d596 100644 --- a/testing/web-platform/mozilla/meta/service-workers/service-worker/fetch-event-async-respond-with.https.html.ini +++ b/testing/web-platform/mozilla/meta/service-workers/service-worker/fetch-event-async-respond-with.https.html.ini @@ -1,3 +1,5 @@ [fetch-event-async-respond-with.https.html] type: testharness - expected: CRASH + expected: OK + [Calling respondWith asynchronously throws an exception] + expected: FAIL diff --git a/testing/web-platform/mozilla/meta/service-workers/service-worker/fetch-event-respond-with-stops-propagation.https.html.ini b/testing/web-platform/mozilla/meta/service-workers/service-worker/fetch-event-respond-with-stops-propagation.https.html.ini index 9bd19343af1..5c8e908b24b 100644 --- a/testing/web-platform/mozilla/meta/service-workers/service-worker/fetch-event-respond-with-stops-propagation.https.html.ini +++ b/testing/web-platform/mozilla/meta/service-workers/service-worker/fetch-event-respond-with-stops-propagation.https.html.ini @@ -1,3 +1,6 @@ [fetch-event-respond-with-stops-propagation.https.html] type: testharness - expected: CRASH + expected: OK + [respondWith() invokes stopImmediatePropagation()] + expected: FAIL +