Bug 990090 - Use AutoJSAPI for BroadcastErrorToSharedWorkers. r=khuey, a=sledru
authorBobby Holley <bobbyholley@gmail.com>
Thu, 12 Jun 2014 10:02:33 -0700
changeset 200213 f1aebc2f1c583b6461d576719a7148c64c4b121d
parent 200212 f436868418ee20934dba0c19fb3457731d58a938
child 200214 899d4310c1c90aa04ac4a612c570d55cb537752f
push id6102
push userryanvm@gmail.com
push dateFri, 13 Jun 2014 13:13:23 +0000
treeherdermozilla-aurora@f1aebc2f1c58 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey, sledru
bugs990090
milestone32.0a2
Bug 990090 - Use AutoJSAPI for BroadcastErrorToSharedWorkers. r=khuey, a=sledru
dom/workers/WorkerPrivate.cpp
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -3122,36 +3122,20 @@ WorkerPrivateParent<Derived>::BroadcastE
   for (size_t index = 0; index < sharedWorkers.Length(); index++) {
     nsRefPtr<SharedWorker>& sharedWorker = sharedWorkers[index];
 
     // May be null.
     nsPIDOMWindow* window = sharedWorker->GetOwner();
 
     size_t actionsIndex = windowActions.LastIndexOf(WindowAction(window));
 
-    // Get the context for this window so that we can report errors correctly.
-    JSContext* cx;
-    rv = NS_OK;
-
-    if (actionsIndex == windowActions.NoIndex) {
-      nsIScriptContext* scx = sharedWorker->GetContextForEventHandlers(&rv);
-      cx = (NS_SUCCEEDED(rv) && scx) ?
-           scx->GetNativeContext() :
-           nsContentUtils::GetSafeJSContext();
-    } else {
-      cx = windowActions[actionsIndex].mJSContext;
-    }
-
-    AutoCxPusher autoPush(cx);
-
-    if (NS_FAILED(rv)) {
-      Throw(cx, rv);
-      JS_ReportPendingException(cx);
-      continue;
-    }
+    nsIGlobalObject* global = sharedWorker->GetParentObject();
+    AutoJSAPIWithErrorsReportedToWindow jsapi(global);
+    JSContext* cx = jsapi.cx();
+    JSAutoCompartment ac(cx, global->GetGlobalJSObject());
 
     RootedDictionary<ErrorEventInit> errorInit(aCx);
     errorInit.mBubbles = false;
     errorInit.mCancelable = true;
     errorInit.mMessage = aMessage;
     errorInit.mFilename = aFilename;
     errorInit.mLineno = aLineNumber;
     errorInit.mColno = aColumnNumber;
@@ -3163,17 +3147,17 @@ WorkerPrivateParent<Derived>::BroadcastE
       Throw(cx, NS_ERROR_UNEXPECTED);
       JS_ReportPendingException(cx);
       continue;
     }
 
     errorEvent->SetTrusted(true);
 
     bool defaultActionEnabled;
-    rv = sharedWorker->DispatchEvent(errorEvent, &defaultActionEnabled);
+    nsresult rv = sharedWorker->DispatchEvent(errorEvent, &defaultActionEnabled);
     if (NS_FAILED(rv)) {
       Throw(cx, rv);
       JS_ReportPendingException(cx);
       continue;
     }
 
     if (defaultActionEnabled) {
       // Add the owning window to our list so that we will fire an error event