Bug 1301796 - Remove racy code in nsCycleCollector::RegisterJSRuntime. r=smaug
MozReview-Commit-ID: 18MW4EYbaC8
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -3430,24 +3430,24 @@ nsCycleCollector::~nsCycleCollector()
}
void
nsCycleCollector::RegisterJSRuntime(CycleCollectedJSRuntime* aJSRuntime)
{
MOZ_RELEASE_ASSERT(!mJSRuntime, "Multiple registrations of JS runtime in cycle collector");
mJSRuntime = aJSRuntime;
+ if (!NS_IsMainThread()) {
+ return;
+ }
+
// We can't register as a reporter in nsCycleCollector() because that runs
// before the memory reporter manager is initialized. So we do it here
// instead.
- static bool registered = false;
- if (!registered) {
- RegisterWeakMemoryReporter(this);
- registered = true;
- }
+ RegisterWeakMemoryReporter(this);
}
void
nsCycleCollector::ForgetJSRuntime()
{
MOZ_RELEASE_ASSERT(mJSRuntime, "Forgetting JS runtime in cycle collector before a JS runtime was registered");
mJSRuntime = nullptr;
}