Bug 1797327 - Use RefPtrs for all WorkerLoadContexts; r=asuth
As WorkerLoadContexts now inherit from a non-CC'd loadContextBase, we have two outcomes. 1) we need to break cycles with ScriptLoadRequests manually, so that ScriptLoadRequests can be collected (ScriptLoadRequests must be CC'd). 2) we can now have refptrs to WorkerLoadContexts in the CacheLoadHandler and NetworkLoadHandler classes, and remove any remaining raw pointers to ScriptLoadRequest/WorkerLoadContext. There are cases where the NetworkLoadHandler or CacheLoadHandler might outlive the Worker Loader, so having refpointers here should help us recover in those cases. Differential Revision: https://phabricator.services.mozilla.com/D160334
This commit is contained in:
@@ -115,6 +115,12 @@ void ScriptLoadRequest::Cancel() {
|
||||
if (HasScriptLoadContext()) {
|
||||
GetScriptLoadContext()->MaybeCancelOffThreadScript();
|
||||
}
|
||||
if (HasWorkerLoadContext()) {
|
||||
// Steal and let the worker load context go out of scope, we
|
||||
// no longer need it.
|
||||
RefPtr<mozilla::dom::WorkerLoadContext> droppedContext =
|
||||
StealWorkerLoadContext();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptLoadRequest::DropBytecodeCacheReferences() {
|
||||
@@ -126,6 +132,10 @@ bool ScriptLoadRequest::HasScriptLoadContext() const {
|
||||
return HasLoadContext() && mLoadContext->IsWindowContext();
|
||||
}
|
||||
|
||||
bool ScriptLoadRequest::HasWorkerLoadContext() const {
|
||||
return HasLoadContext() && mLoadContext->IsWorkerContext();
|
||||
}
|
||||
|
||||
mozilla::dom::ScriptLoadContext* ScriptLoadRequest::GetScriptLoadContext() {
|
||||
MOZ_ASSERT(mLoadContext);
|
||||
return mLoadContext->AsWindowContext();
|
||||
@@ -142,6 +152,17 @@ mozilla::dom::WorkerLoadContext* ScriptLoadRequest::GetWorkerLoadContext() {
|
||||
return mLoadContext->AsWorkerContext();
|
||||
}
|
||||
|
||||
already_AddRefed<mozilla::dom::WorkerLoadContext>
|
||||
ScriptLoadRequest::StealWorkerLoadContext() {
|
||||
MOZ_ASSERT(mLoadContext);
|
||||
RefPtr<mozilla::dom::WorkerLoadContext> workerContext =
|
||||
mLoadContext->AsWorkerContext();
|
||||
// Break cycle.
|
||||
mLoadContext->mRequest = nullptr;
|
||||
mLoadContext = nullptr;
|
||||
return workerContext.forget();
|
||||
}
|
||||
|
||||
ModuleLoadRequest* ScriptLoadRequest::AsModuleRequest() {
|
||||
MOZ_ASSERT(IsModuleRequest());
|
||||
return static_cast<ModuleLoadRequest*>(this);
|
||||
|
||||
Reference in New Issue
Block a user