summaryrefslogtreecommitdiff
path: root/dom
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2022-02-11 14:15:10 +0000
committerMoonchild <moonchild@palemoon.org>2022-02-11 14:15:10 +0000
commite1f684cafe689f572bec6aa4265b8af6df6a2712 (patch)
tree0f4b998c4ea47c1ce1c78c833b0bb518b59cf970 /dom
parent5545fc05b7fd6db8bb82f2884b62ca5feda9880c (diff)
downloadaura-central-e1f684cafe689f572bec6aa4265b8af6df6a2712.tar.gz
[DOM] Promise worker-proxy cleanup improvements
Diffstat (limited to 'dom')
-rw-r--r--dom/promise/Promise.cpp39
-rw-r--r--dom/promise/PromiseWorkerProxy.h3
2 files changed, 16 insertions, 26 deletions
diff --git a/dom/promise/Promise.cpp b/dom/promise/Promise.cpp
index 4b9736d79..38db74b02 100644
--- a/dom/promise/Promise.cpp
+++ b/dom/promise/Promise.cpp
@@ -730,12 +730,17 @@ PromiseWorkerProxy::Create(WorkerPrivate* aWorkerPrivate,
RefPtr<PromiseWorkerProxy> proxy =
new PromiseWorkerProxy(aWorkerPrivate, aWorkerPromise, aCb);
+ // Maintain a reference so that we have a valid object to clean up when
+ // removing the feature.
+ proxy.get()->AddRef();
+
// We do this to make sure the worker thread won't shut down before the
// promise is resolved/rejected on the worker thread.
if (!proxy->AddRefObject()) {
// Probably the worker is terminating. We cannot complete the operation
- // and we have to release all the resources.
- proxy->CleanProperties();
+ // and we have to release all the resources. CleanUp releases the extra
+ // ref, too
+ proxy->CleanUp();
return nullptr;
}
@@ -763,24 +768,6 @@ PromiseWorkerProxy::~PromiseWorkerProxy()
MOZ_ASSERT(!mWorkerPrivate);
}
-void
-PromiseWorkerProxy::CleanProperties()
-{
-#ifdef DEBUG
- WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
- MOZ_ASSERT(worker);
- worker->AssertIsOnWorkerThread();
-#endif
- // Ok to do this unprotected from Create().
- // CleanUp() holds the lock before calling this.
- mCleanedUp = true;
- mWorkerPromise = nullptr;
- mWorkerPrivate = nullptr;
-
- // Clear the StructuredCloneHolderBase class.
- Clear();
-}
-
bool
PromiseWorkerProxy::AddRefObject()
{
@@ -881,8 +868,9 @@ PromiseWorkerProxy::CleanUp()
return;
}
- MOZ_ASSERT(mWorkerPrivate);
- mWorkerPrivate->AssertIsOnWorkerThread();
+ if (mWorkerPrivate) {
+ mWorkerPrivate->AssertIsOnWorkerThread();
+ }
// Release the Promise and remove the PromiseWorkerProxy from the holders of
// the worker thread since the Promise has been resolved/rejected or the
@@ -890,7 +878,12 @@ PromiseWorkerProxy::CleanUp()
MOZ_ASSERT(mWorkerHolder);
mWorkerHolder = nullptr;
- CleanProperties();
+ mCleanedUp = true;
+ mWorkerPromise = nullptr;
+ mWorkerPrivate = nullptr;
+
+ // Clear the StructuredCloneHolderBase class.
+ Clear();
}
Release();
}
diff --git a/dom/promise/PromiseWorkerProxy.h b/dom/promise/PromiseWorkerProxy.h
index 3b0e443a4..1c7052860 100644
--- a/dom/promise/PromiseWorkerProxy.h
+++ b/dom/promise/PromiseWorkerProxy.h
@@ -190,9 +190,6 @@ private:
bool AddRefObject();
- // If not called from Create(), be sure to hold Lock().
- void CleanProperties();
-
// Function pointer for calling Promise::{ResolveInternal,RejectInternal}.
typedef void (Promise::*RunCallbackFunc)(JSContext*,
JS::Handle<JS::Value>);