diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index c6de6aeaabb0..af627f33d86d 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -2495,6 +2495,11 @@ already_AddRefed WorkerPrivate::Constructor( return nullptr; } + // From this point on (worker thread has been started) we + // must keep ourself alive. We can now only be cleared by + // ClearSelfAndParentEventTargetRef(). + worker->mSelfRef = worker; + worker->EnableDebugger(); MOZ_DIAGNOSTIC_ASSERT(worker->PrincipalIsValid()); @@ -2511,8 +2516,6 @@ already_AddRefed WorkerPrivate::Constructor( return nullptr; } - worker->mSelfRef = worker; - return worker.forget(); }