Bug 1151646 - Spin the event loop one extra time to clean up all CC'd objects before worker shutdown, r=khuey.

This commit is contained in:
Ben Turner 2015-04-08 15:20:59 -07:00
parent a1dae92265
commit f6cb233b56
2 changed files with 12 additions and 9 deletions

View File

@ -2762,15 +2762,18 @@ WorkerThreadPrimaryRunnable::Run()
#endif #endif
} }
// Destroy the main context. This will unroot the main worker global and // Destroy the main context. This will unroot the main worker global and GC,
// GC. This is not the last JSContext (WorkerJSRuntime maintains an // which should break all cycles that touch JS.
// internal JSContext).
JS_DestroyContext(cx); JS_DestroyContext(cx);
// Before shutting down the cycle collector we need to do one more pass
// through the event loop to clean up any C++ objects that need deferred
// cleanup.
mWorkerPrivate->ClearMainEventQueue(WorkerPrivate::WorkerRan);
// Now WorkerJSRuntime goes out of scope and its destructor will shut // Now WorkerJSRuntime goes out of scope and its destructor will shut
// down the cycle collector and destroy the final JSContext. This // down the cycle collector. This breaks any remaining cycles and collects
// breaks any remaining cycles and collects the C++ and JS objects // any remaining C++ objects.
// participating.
} }
mWorkerPrivate->SetThread(nullptr); mWorkerPrivate->SetThread(nullptr);

View File

@ -1210,6 +1210,9 @@ public:
return mCancelAllPendingRunnables; return mCancelAllPendingRunnables;
} }
void
ClearMainEventQueue(WorkerRanOrNot aRanOrNot);
void void
OnProcessNextEvent(uint32_t aRecursionDepth); OnProcessNextEvent(uint32_t aRecursionDepth);
@ -1252,9 +1255,6 @@ private:
WorkerType aWorkerType, const nsACString& aSharedWorkerName, WorkerType aWorkerType, const nsACString& aSharedWorkerName,
WorkerLoadInfo& aLoadInfo); WorkerLoadInfo& aLoadInfo);
void
ClearMainEventQueue(WorkerRanOrNot aRanOrNot);
bool bool
MayContinueRunning() MayContinueRunning()
{ {