Bug 1070131 - Reduce the cases where we dispatch nsScriptErrorEvent. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Mon, 29 Sep 2014 10:44:29 +0200
changeset 207664 1e4da0087b72e306f9aa78d69b1465c17fe775d2
parent 207663 1abe619810bb72b8919dcdea4d82c2f5c7af69f0
child 207665 b9bfd9b37fe82071ac5da7360608fd301f98e57e
push id27564
push userryanvm@gmail.com
push dateMon, 29 Sep 2014 18:57:04 +0000
treeherdermozilla-central@ce9a0b34225e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1070131
milestone35.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 1070131 - Reduce the cases where we dispatch nsScriptErrorEvent. r=bz
dom/base/nsJSEnvironment.cpp
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -349,35 +349,30 @@ NS_HandleScriptError(nsIScriptGlobalObje
 }
 
 class ScriptErrorEvent : public nsRunnable
 {
 public:
   ScriptErrorEvent(JSRuntime* aRuntime,
                    xpc::ErrorReport* aReport,
                    nsIPrincipal* aScriptOriginPrincipal,
-                   JS::Handle<JS::Value> aError,
-                   bool aDispatchEvent)
+                   JS::Handle<JS::Value> aError)
     : mReport(aReport)
     , mOriginPrincipal(aScriptOriginPrincipal)
-    , mDispatchEvent(aDispatchEvent)
     , mError(aRuntime, aError)
   {}
 
   NS_IMETHOD Run()
   {
     nsEventStatus status = nsEventStatus_eIgnore;
     nsPIDOMWindow* win = mReport->mWindow;
     MOZ_ASSERT(win);
     // First, notify the DOM that we have a script error, but only if
     // our window is still the current inner.
-    if (mDispatchEvent && win->IsCurrentInnerWindow() &&
-        win->GetDocShell() && !JSREPORT_IS_WARNING(mReport->mFlags) &&
-        !sHandlingScriptError)
-    {
+    if (win->IsCurrentInnerWindow() && win->GetDocShell() && !sHandlingScriptError) {
       AutoRestore<bool> recursionGuard(sHandlingScriptError);
       sHandlingScriptError = true;
 
       nsRefPtr<nsPresContext> presContext;
       win->GetDocShell()->GetPresContext(getter_AddRefs(presContext));
 
       ThreadsafeAutoJSContext cx;
       RootedDictionary<ErrorEventInit> init(cx);
@@ -424,17 +419,16 @@ public:
     }
 
     return NS_OK;
   }
 
 private:
   nsRefPtr<xpc::ErrorReport>      mReport;
   nsCOMPtr<nsIPrincipal>          mOriginPrincipal;
-  bool                            mDispatchEvent;
   JS::PersistentRootedValue       mError;
 
   static bool sHandlingScriptError;
 };
 
 bool ScriptErrorEvent::sHandlingScriptError = false;
 
 // This temporarily lives here to avoid code churn. It will go away entirely
@@ -486,38 +480,33 @@ SystemErrorReporter(JSContext *cx, const
   if (!globalObject) {
     globalObject = xpc::NativeGlobal(xpc::PrivilegedJunkScope());
   }
 
   if (globalObject) {
     nsRefPtr<xpc::ErrorReport> xpcReport = new xpc::ErrorReport();
     xpcReport->Init(report, message, globalObject);
 
-    // If there's no window to fire an event at, report it to the console
-    // directly.
-    if (!xpcReport->mWindow) {
+    // If we can't dispatch an event to a window, report it to the console
+    // directly. This includes the case where the error was an OOM, because
+    // triggering a scripted event handler is likely to generate further OOMs.
+    if (!xpcReport->mWindow || JSREPORT_IS_WARNING(xpcReport->mFlags) ||
+        report->errorNumber == JSMSG_OUT_OF_MEMORY)
+    {
       xpcReport->LogToConsole();
       return;
     }
 
     // Otherwise, we need to asynchronously invoke onerror before we can decide
     // whether or not to report the error to the console.
     nsContentUtils::AddScriptRunner(
       new ScriptErrorEvent(JS_GetRuntime(cx),
                            xpcReport,
                            nsJSPrincipals::get(report->originPrincipals),
-                           exception,
-                           /* We do not try to report Out Of Memory via a dom
-                            * event because the dom event handler would
-                            * encounter an OOM exception trying to process the
-                            * event, and then we'd need to generate a new OOM
-                            * event for that new OOM instance -- this isn't
-                            * pretty.
-                            */
-                           report->errorNumber != JSMSG_OUT_OF_MEMORY));
+                           exception));
   }
 }
 
 } /* namespace xpc */
 
 #ifdef DEBUG
 // A couple of useful functions to call when you're debugging.
 nsGlobalWindow *