Bug 1874080 - Nullify WebTaskSchedulerWorker::mWorkerPrivate while Disconnect(). r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D198569
This commit is contained in:
Eden Chuang 2024-01-15 15:53:56 +00:00
parent 03343bf403
commit 1f89c187e9
3 changed files with 16 additions and 1 deletions

View File

@ -145,7 +145,7 @@ class WebTaskScheduler : public nsWrapperCache, public SupportsWeakPtr {
WebTask* GetNextTask() const;
void Disconnect();
virtual void Disconnect();
void RunTaskSignalPriorityChange(TaskSignal* aTaskSignal);

View File

@ -36,6 +36,9 @@ bool WebTaskWorkerRunnable::WorkerRun(JSContext* aCx,
nsresult WebTaskSchedulerWorker::SetTimeoutForDelayedTask(WebTask* aTask,
uint64_t aDelay) {
if (!mWorkerPrivate) {
return NS_ERROR_UNEXPECTED;
}
JSContext* cx = nsContentUtils::GetCurrentJSContext();
if (!cx) {
return NS_ERROR_UNEXPECTED;
@ -52,8 +55,18 @@ nsresult WebTaskSchedulerWorker::SetTimeoutForDelayedTask(WebTask* aTask,
}
bool WebTaskSchedulerWorker::DispatchEventLoopRunnable() {
if (!mWorkerPrivate) {
return false;
}
RefPtr<WebTaskWorkerRunnable> runnable =
new WebTaskWorkerRunnable(mWorkerPrivate, this);
return runnable->Dispatch();
}
void WebTaskSchedulerWorker::Disconnect() {
if (mWorkerPrivate) {
mWorkerPrivate = nullptr;
}
WebTaskScheduler::Disconnect();
}
} // namespace mozilla::dom

View File

@ -34,6 +34,8 @@ class WebTaskSchedulerWorker final : public WebTaskScheduler {
public:
explicit WebTaskSchedulerWorker(WorkerPrivate* aWorkerPrivate);
void Disconnect() override;
private:
~WebTaskSchedulerWorker() = default;