Bug 979951: Always preserve the worker wrapper to ensure that we have something to tell us what compartment to enter. r=bent
authorKyle Huey <khuey@kylehuey.com>
Wed, 05 Mar 2014 17:58:03 -0800
changeset 172175 b077aaea25e77f121ba0dada32f66520cfa5e7fb
parent 172174 c50ed275755175aad660d950a0882f6c2ff12af9
child 172176 2e6afd113f7a8ec41adb17b5fb1e80d5c179a811
push idunknown
push userunknown
push dateunknown
reviewersbent
bugs979951
milestone30.0a1
Bug 979951: Always preserve the worker wrapper to ensure that we have something to tell us what compartment to enter. r=bent
dom/workers/WorkerPrivate.cpp
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -2137,17 +2137,25 @@ JSObject*
 WorkerPrivateParent<Derived>::WrapObject(JSContext* aCx,
                                          JS::Handle<JSObject*> aScope)
 {
   MOZ_ASSERT(!IsSharedWorker(),
              "We should never wrap a WorkerPrivate for a SharedWorker");
 
   AssertIsOnParentThread();
 
-  return WorkerBinding::Wrap(aCx, aScope, ParentAsWorkerPrivate());
+  // XXXkhuey this should not need to be rooted, the analysis is dumb.
+  // See bug 980181.
+  JS::Rooted<JSObject*> wrapper(aCx,
+    WorkerBinding::Wrap(aCx, aScope, ParentAsWorkerPrivate()));
+  if (wrapper) {
+    MOZ_ALWAYS_TRUE(TryPreserveWrapper(wrapper));
+  }
+
+  return wrapper;
 }
 
 template <class Derived>
 nsresult
 WorkerPrivateParent<Derived>::DispatchPrivate(WorkerRunnable* aRunnable,
                                               nsIEventTarget* aSyncLoopTarget)
 {
   // May be called on any thread!