Bug 1030707 - Part 5: Replace AutoPushJSContext in SynchronizeAndResumeRunnable::Run. r=bholley
authorBob Owen <bobowencode@gmail.com>
Tue, 01 Jul 2014 11:25:27 +0100
changeset 212715 98bdfcb393d055778a9afbae53ae63eb79fcf9b6
parent 212714 49a7c1aa4ae1a329c1187ad5a4dc5b375094b19b
child 212716 9c0edda6d34b09da2951610bc95a1c3e3408c43c
push id3857
push userraliiev@mozilla.com
push dateTue, 02 Sep 2014 16:39:23 +0000
treeherdermozilla-beta@5638b907b505 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1030707
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1030707 - Part 5: Replace AutoPushJSContext in SynchronizeAndResumeRunnable::Run. r=bholley
dom/workers/RuntimeService.cpp
dom/workers/WorkerPrivate.cpp
dom/workers/WorkerPrivate.h
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -2128,17 +2128,17 @@ RuntimeService::ResumeWorkersForWindow(n
 
     nsIScriptContext* scx = sgo->GetContext();
 
     AutoPushJSContext cx(scx ?
                          scx->GetNativeContext() :
                          nsContentUtils::GetSafeJSContext());
 
     for (uint32_t index = 0; index < workers.Length(); index++) {
-      if (!workers[index]->SynchronizeAndResume(cx, aWindow, scx)) {
+      if (!workers[index]->SynchronizeAndResume(cx, aWindow)) {
         JS_ReportPendingException(cx);
       }
     }
   }
 }
 
 nsresult
 RuntimeService::CreateServiceWorker(const GlobalObject& aGlobal,
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -42,16 +42,17 @@
 #include "mozilla/dom/ErrorEventBinding.h"
 #include "mozilla/dom/Exceptions.h"
 #include "mozilla/dom/FunctionBinding.h"
 #include "mozilla/dom/ImageData.h"
 #include "mozilla/dom/ImageDataBinding.h"
 #include "mozilla/dom/MessageEvent.h"
 #include "mozilla/dom/MessageEventBinding.h"
 #include "mozilla/dom/MessagePortList.h"
+#include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/dom/WorkerBinding.h"
 #include "mozilla/Preferences.h"
 #include "nsAlgorithm.h"
 #include "nsContentUtils.h"
 #include "nsCxPusher.h"
 #include "nsError.h"
 #include "nsDOMJSUtils.h"
 #include "nsHostObjectProtocolHandler.h"
@@ -1838,24 +1839,21 @@ NS_IMPL_ISUPPORTS(TimerThreadEventTarget
 template <class Derived>
 class WorkerPrivateParent<Derived>::SynchronizeAndResumeRunnable MOZ_FINAL
   : public nsRunnable
 {
   friend class nsRevocableEventPtr<SynchronizeAndResumeRunnable>;
 
   WorkerPrivate* mWorkerPrivate;
   nsCOMPtr<nsPIDOMWindow> mWindow;
-  nsCOMPtr<nsIScriptContext> mScriptContext;
 
 public:
   SynchronizeAndResumeRunnable(WorkerPrivate* aWorkerPrivate,
-                               nsPIDOMWindow* aWindow,
-                               nsIScriptContext* aScriptContext)
-  : mWorkerPrivate(aWorkerPrivate), mWindow(aWindow),
-    mScriptContext(aScriptContext)
+                               nsPIDOMWindow* aWindow)
+  : mWorkerPrivate(aWorkerPrivate), mWindow(aWindow)
   {
     AssertIsOnMainThread();
     MOZ_ASSERT(aWorkerPrivate);
     MOZ_ASSERT(aWindow);
     MOZ_ASSERT(!aWorkerPrivate->GetParent());
   }
 
 private:
@@ -1863,19 +1861,21 @@ private:
   { }
 
   NS_IMETHOD
   Run() MOZ_OVERRIDE
   {
     AssertIsOnMainThread();
 
     if (mWorkerPrivate) {
-      AutoPushJSContext cx(mScriptContext ?
-                           mScriptContext->GetNativeContext() :
-                           nsContentUtils::GetSafeJSContext());
+      AutoJSAPI jsapi;
+      if (NS_WARN_IF(!jsapi.InitWithLegacyErrorReporting(mWindow))) {
+        return NS_OK;
+      }
+      JSContext* cx = jsapi.cx();
 
       if (!mWorkerPrivate->Resume(cx, mWindow)) {
         JS_ReportPendingException(cx);
       }
     }
 
     return NS_OK;
   }
@@ -1884,17 +1884,16 @@ private:
   Revoke()
   {
     AssertIsOnMainThread();
     MOZ_ASSERT(mWorkerPrivate);
     MOZ_ASSERT(mWindow);
 
     mWorkerPrivate = nullptr;
     mWindow = nullptr;
-    mScriptContext = nullptr;
   }
 };
 
 template <class Derived>
 class WorkerPrivateParent<Derived>::EventTarget MOZ_FINAL
   : public nsIEventTarget
 {
   // This mutex protects mWorkerPrivate and must be acquired *before* the
@@ -2604,32 +2603,30 @@ WorkerPrivateParent<Derived>::Resume(JSC
 
   return true;
 }
 
 template <class Derived>
 bool
 WorkerPrivateParent<Derived>::SynchronizeAndResume(
                                                JSContext* aCx,
-                                               nsPIDOMWindow* aWindow,
-                                               nsIScriptContext* aScriptContext)
+                                               nsPIDOMWindow* aWindow)
 {
   AssertIsOnMainThread();
   MOZ_ASSERT(!GetParent());
   MOZ_ASSERT_IF(IsDedicatedWorker(), mParentSuspended);
 
   // NB: There may be pending unqueued messages.  If we resume here we will
   // execute those messages out of order.  Instead we post an event to the
   // end of the event queue, allowing all of the outstanding messages to be
   // queued up in order on the worker.  Then and only then we execute all of
   // the messages.
 
   nsRefPtr<SynchronizeAndResumeRunnable> runnable =
-    new SynchronizeAndResumeRunnable(ParentAsWorkerPrivate(), aWindow,
-                                     aScriptContext);
+    new SynchronizeAndResumeRunnable(ParentAsWorkerPrivate(), aWindow);
   if (NS_FAILED(NS_DispatchToCurrentThread(runnable))) {
     JS_ReportError(aCx, "Failed to dispatch to current thread!");
     return false;
   }
 
   mSynchronizeRunnable = runnable;
   return true;
 }
--- a/dom/workers/WorkerPrivate.h
+++ b/dom/workers/WorkerPrivate.h
@@ -334,25 +334,27 @@ public:
   }
 
   bool
   Kill(JSContext* aCx)
   {
     return Notify(aCx, Killing);
   }
 
+  // We can assume that an nsPIDOMWindow will be available for Suspend, Resume
+  // and SynchronizeAndResume as these are only used for globals going in and
+  // out of the bfcache.
   bool
   Suspend(JSContext* aCx, nsPIDOMWindow* aWindow);
 
   bool
   Resume(JSContext* aCx, nsPIDOMWindow* aWindow);
 
   bool
-  SynchronizeAndResume(JSContext* aCx, nsPIDOMWindow* aWindow,
-                       nsIScriptContext* aScriptContext);
+  SynchronizeAndResume(JSContext* aCx, nsPIDOMWindow* aWindow);
 
   bool
   Terminate(JSContext* aCx)
   {
     AssertIsOnParentThread();
     return TerminatePrivate(aCx);
   }