From 7ed1ee4d7d38c655edd2635b88ace6ef0c0f4aa2 Mon Sep 17 00:00:00 2001 From: Catalin Badea Date: Thu, 13 Aug 2015 13:35:10 -0700 Subject: [PATCH] Bug 1193133 - Throw when calling postMessage from a Service Worker dom object with no global. r=bkelly --- dom/workers/ServiceWorker.cpp | 15 ++++++++++----- .../fetch-event-async-respond-with.https.html.ini | 4 +++- ...-respond-with-stops-propagation.https.html.ini | 5 ++++- 3 files changed, 17 insertions(+), 7 deletions(-) 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 +