Bug 1457157 P2 Clear a worker's ClientSource when it reaches Terminating. r=baku

This commit is contained in:
Ben Kelly 2018-05-02 06:29:26 -07:00
Родитель 0ece66c8ff
Коммит 00d42d9d6b
6 изменённых файлов: 40 добавлений и 15 удалений

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

@ -535,8 +535,14 @@ FetchRequest(nsIGlobalObject* aGlobal, const RequestOrUSVString& aInput,
return nullptr;
}
Maybe<ClientInfo> clientInfo(worker->GetClientInfo());
if (clientInfo.isNothing()) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return nullptr;
}
RefPtr<MainThreadFetchRunnable> run =
new MainThreadFetchRunnable(resolver, worker->GetClientInfo(),
new MainThreadFetchRunnable(resolver, clientInfo.ref(),
worker->GetController(), r);
worker->DispatchToMainThread(run.forget());
}

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

@ -1910,7 +1910,9 @@ public:
: WorkerMainThreadRunnable(aParentWorker,
NS_LITERAL_CSTRING("ScriptLoader :: ChannelGetter"))
, mScriptURL(aScriptURL)
, mClientInfo(aParentWorker->GetClientInfo())
// ClientInfo should always be present since this should not be called
// if parent's status is greater than Running.
, mClientInfo(aParentWorker->GetClientInfo().ref())
, mLoadInfo(aLoadInfo)
, mResult(NS_ERROR_FAILURE)
{
@ -2246,7 +2248,7 @@ LoadAllScripts(WorkerPrivate* aWorkerPrivate,
Maybe<ClientInfo> clientInfo;
Maybe<ServiceWorkerDescriptor> controller;
if (!aIsMainScript) {
clientInfo.emplace(aWorkerPrivate->GetClientInfo());
clientInfo = aWorkerPrivate->GetClientInfo();
controller = aWorkerPrivate->GetController();
}
@ -2390,7 +2392,7 @@ LoadMainScript(WorkerPrivate* aWorkerPrivate,
// We are loading the main script, so the worker's Client must be
// reserved.
info->mReservedClientInfo.emplace(aWorkerPrivate->GetClientInfo());
info->mReservedClientInfo = aWorkerPrivate->GetClientInfo();
LoadAllScripts(aWorkerPrivate, loadInfos, true, aWorkerScriptType, aRv);
}

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

@ -3278,12 +3278,14 @@ WorkerPrivate::DoRunLoop(JSContext* aCx)
// If we're supposed to die then we should exit the loop.
if (currentStatus == Killing) {
// The ClientSource should be cleared in NotifyInternal() when we reach
// or pass Terminating.
MOZ_DIAGNOSTIC_ASSERT(!mClientSource);
// Flush uncaught rejections immediately, without
// waiting for a next tick.
PromiseDebugging::FlushUncaughtRejections();
mClientSource = nullptr;
ShutdownGCTimers();
DisableMemoryReporter();
@ -3500,12 +3502,17 @@ WorkerPrivate::EnsurePerformanceStorage()
}
}
const ClientInfo&
Maybe<ClientInfo>
WorkerPrivate::GetClientInfo() const
{
AssertIsOnWorkerThread();
MOZ_DIAGNOSTIC_ASSERT(mClientSource);
return mClientSource->Info();
Maybe<ClientInfo> clientInfo;
if (!mClientSource) {
MOZ_DIAGNOSTIC_ASSERT(mStatus >= Terminating);
return Move(clientInfo);
}
clientInfo.emplace(mClientSource->Info());
return Move(clientInfo);
}
const ClientState
@ -3540,6 +3547,12 @@ void
WorkerPrivate::ExecutionReady()
{
AssertIsOnWorkerThread();
{
MutexAutoLock lock(mMutex);
if (mStatus >= Terminating) {
return;
}
}
MOZ_DIAGNOSTIC_ASSERT(mClientSource);
mClientSource->WorkerExecutionReady(this);
}
@ -4514,8 +4527,9 @@ WorkerPrivate::NotifyInternal(WorkerStatus aStatus)
}
if (aStatus >= Terminating) {
MutexAutoUnlock unlock(mMutex);
mClientSource.reset();
if (mScope) {
MutexAutoUnlock unlock(mMutex);
mScope->NoteTerminating();
}
}

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

@ -553,7 +553,7 @@ public:
void
EnsurePerformanceCounter();
const ClientInfo&
Maybe<ClientInfo>
GetClientInfo() const;
const ClientState

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

@ -546,9 +546,7 @@ WorkerGlobalScope::AbstractMainThreadFor(TaskCategory aCategory)
Maybe<ClientInfo>
WorkerGlobalScope::GetClientInfo() const
{
Maybe<ClientInfo> info;
info.emplace(mWorkerPrivate->GetClientInfo());
return Move(info);
return mWorkerPrivate->GetClientInfo();
}
Maybe<ClientState>

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

@ -1875,7 +1875,12 @@ XMLHttpRequestWorker::Open(const nsACString& aMethod,
}
}
else {
mProxy = new Proxy(this, mWorkerPrivate->GetClientInfo(),
Maybe<ClientInfo> clientInfo(mWorkerPrivate->GetClientInfo());
if (clientInfo.isNothing()) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
mProxy = new Proxy(this, clientInfo.ref(),
mWorkerPrivate->GetController(), mMozAnon, mMozSystem);
}