Bug 1349266 - Using a workerHolder to keep alive a parent worker when a child worker is created, r=kbelly

This commit is contained in:
Andrea Marchesini 2017-05-25 09:04:25 +02:00
Родитель 56bfed781d
Коммит 8cfd4ae66c
1 изменённых файлов: 16 добавлений и 0 удалений

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

@ -1595,6 +1595,12 @@ PRThreadFromThread(nsIThread* aThread)
return result; return result;
} }
class SimpleWorkerHolder final : public WorkerHolder
{
public:
virtual bool Notify(Status aStatus) { return true; }
};
} /* anonymous namespace */ } /* anonymous namespace */
NS_IMPL_ISUPPORTS_INHERITED0(MainThreadReleaseRunnable, Runnable) NS_IMPL_ISUPPORTS_INHERITED0(MainThreadReleaseRunnable, Runnable)
@ -4579,11 +4585,21 @@ WorkerPrivate::Constructor(JSContext* aCx,
const nsACString& aServiceWorkerScope, const nsACString& aServiceWorkerScope,
WorkerLoadInfo* aLoadInfo, ErrorResult& aRv) WorkerLoadInfo* aLoadInfo, ErrorResult& aRv)
{ {
// If this is a sub-worker, we need to keep the parent worker alive until this
// one is registered.
UniquePtr<SimpleWorkerHolder> holder;
WorkerPrivate* parent = NS_IsMainThread() ? WorkerPrivate* parent = NS_IsMainThread() ?
nullptr : nullptr :
GetCurrentThreadWorkerPrivate(); GetCurrentThreadWorkerPrivate();
if (parent) { if (parent) {
parent->AssertIsOnWorkerThread(); parent->AssertIsOnWorkerThread();
holder.reset(new SimpleWorkerHolder());
if (!holder->HoldWorker(parent, Canceling)) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return nullptr;
}
} else { } else {
AssertIsOnMainThread(); AssertIsOnMainThread();
} }