Bug 1610692 - Move call that can run content code out of constructor. r=dom-workers-and-storage-reviewers,asuth

ServiceWorkerRegistration::UpdateState can call content code, which
in turn can result in the registrations getting deleted. This
commit moves the call outside the constructor, so the
registration's creator has a chance to get a proper RefPtr to it.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Yaron Tausky 2020-02-20 13:06:18 +00:00
Родитель 1624e3f67f
Коммит 5c6bfb7d9a
1 изменённых файлов: 8 добавлений и 1 удалений

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

@ -50,7 +50,6 @@ ServiceWorkerRegistration::ServiceWorkerRegistration(
KeepAliveIfHasListenersFor(NS_LITERAL_STRING("updatefound")); KeepAliveIfHasListenersFor(NS_LITERAL_STRING("updatefound"));
UpdateState(mDescriptor);
mInner->SetServiceWorkerRegistration(this); mInner->SetServiceWorkerRegistration(this);
} }
@ -81,6 +80,10 @@ ServiceWorkerRegistration::CreateForMainThread(
RefPtr<ServiceWorkerRegistration> registration = RefPtr<ServiceWorkerRegistration> registration =
new ServiceWorkerRegistration(aWindow->AsGlobal(), aDescriptor, inner); new ServiceWorkerRegistration(aWindow->AsGlobal(), aDescriptor, inner);
// This is not called from within the constructor, as it may call content code
// which can cause the deletion of the registration, so we need to keep a
// strong reference while calling it.
registration->UpdateState(aDescriptor);
return registration.forget(); return registration.forget();
} }
@ -104,6 +107,10 @@ ServiceWorkerRegistration::CreateForWorker(
RefPtr<ServiceWorkerRegistration> registration = RefPtr<ServiceWorkerRegistration> registration =
new ServiceWorkerRegistration(aGlobal, aDescriptor, inner); new ServiceWorkerRegistration(aGlobal, aDescriptor, inner);
// This is not called from within the constructor, as it may call content code
// which can cause the deletion of the registration, so we need to keep a
// strong reference while calling it.
registration->UpdateState(aDescriptor);
return registration.forget(); return registration.forget();
} }