Bug 1557732 - Don't create worker for discarded document. r=dom-workers-and-storage-reviewers,asuth

Differential Revision: https://phabricator.services.mozilla.com/D62608

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Eden Chuang 2020-02-20 14:05:14 +00:00
Родитель 6d32b7af50
Коммит 88ad97f84e
1 изменённых файлов: 10 добавлений и 3 удалений

Просмотреть файл

@ -29,6 +29,16 @@ already_AddRefed<Worker> Worker::Constructor(const GlobalObject& aGlobal,
ErrorResult& aRv) {
JSContext* cx = aGlobal.Context();
nsCOMPtr<nsIGlobalObject> globalObject =
do_QueryInterface(aGlobal.GetAsSupports());
if (globalObject->AsInnerWindow() &&
!globalObject->AsInnerWindow()->IsCurrentInnerWindow()) {
aRv.ThrowInvalidStateError(
"Cannot create worker for a going to be discarded document");
return nullptr;
}
RefPtr<WorkerPrivate> workerPrivate = WorkerPrivate::Constructor(
cx, aScriptURL, false /* aIsChromeWorker */, WorkerTypeDedicated,
aOptions.mName, VoidCString(), nullptr /*aLoadInfo */, aRv);
@ -36,9 +46,6 @@ already_AddRefed<Worker> Worker::Constructor(const GlobalObject& aGlobal,
return nullptr;
}
nsCOMPtr<nsIGlobalObject> globalObject =
do_QueryInterface(aGlobal.GetAsSupports());
RefPtr<Worker> worker = new Worker(globalObject, workerPrivate.forget());
return worker.forget();
}