summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2022-02-11 14:15:10 +0000
committerMoonchild <moonchild@palemoon.org>2022-04-03 01:15:07 +0200
commit5a5bd92efa0616efe393833fca1ba2de1d0f3093 (patch)
tree199b52b3801d12f5e2d49638f84097f949b24b71
parent33b9fbcf2c6c7eb81b1238c1f1fb315ef45560d4 (diff)
downloaduxp-5a5bd92efa0616efe393833fca1ba2de1d0f3093.tar.gz
[DOM] Promise worker-proxy cleanup improvementsRB_29.4.5-UXP
-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 4b9736d79c..38db74b020 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 3b0e443a46..1c70528602 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>);