Bug 1193133 - Throw when calling postMessage from a Service Worker dom object with no global. r=bkelly

This commit is contained in:
Catalin Badea 2015-08-13 13:35:10 -07:00
parent d6eb43737c
commit 7de33f8307
3 changed files with 17 additions and 7 deletions

View File

@ -90,17 +90,22 @@ ServiceWorker::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
const Optional<Sequence<JS::Value>>& aTransferable,
ErrorResult& aRv)
{
WorkerPrivate* workerPrivate = GetWorkerPrivate();
MOZ_ASSERT(workerPrivate);
if (State() == ServiceWorkerState::Redundant) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(GetParentObject());
nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
nsAutoPtr<ServiceWorkerClientInfo> 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<ServiceWorkerClientInfo> clientInfo(new ServiceWorkerClientInfo(window->GetExtantDoc()));
workerPrivate->PostMessageToServiceWorker(aCx, aMessage, aTransferable,
clientInfo, aRv);

View File

@ -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

View File

@ -1,3 +1,6 @@
[fetch-event-respond-with-stops-propagation.https.html]
type: testharness
expected: CRASH
expected: OK
[respondWith() invokes stopImmediatePropagation()]
expected: FAIL