Bug 990090 - Use AutoJSAPI for BroadcastErrorToSharedWorkers. r=khuey, a=sledru
--- 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