Bug 1098025 - Remove the manual ReportPendingException from XULDocument::ExecuteScript; r=bholley
authorTerrence Cole <terrence@mozilla.com>
Wed, 12 Nov 2014 15:12:13 -0800
changeset 215527 e2be5d0449c5eea1f4395c737c53baf3f4e4780a
parent 215526 657e8b81c02dd70dd04cce286edffa35a7b1bf01
child 215528 5e645894f6bf0b32c5d17823b44c91863c1b3beb
push id27818
push userryanvm@gmail.com
push dateThu, 13 Nov 2014 20:19:09 +0000
treeherdermozilla-central@292ed84594c1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1098025
milestone36.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 1098025 - Remove the manual ReportPendingException from XULDocument::ExecuteScript; r=bholley
dom/xul/XULDocument.cpp
dom/xul/test/chrome.ini
dom/xul/test/test_bug1070049_throw_from_script.xul
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -3574,33 +3574,33 @@ XULDocument::ExecuteScript(nsXULPrototyp
     NS_ENSURE_TRUE(scriptObject, NS_ERROR_UNEXPECTED);
 
     // Execute the precompiled script with the given version
     nsAutoMicroTask mt;
 
     // We're about to run script via JS::CloneAndExecuteScript, so we need an
     // AutoEntryScript. This is Gecko specific and not in any spec.
     AutoEntryScript aes(mScriptGlobalObject);
+    aes.TakeOwnershipOfErrorReporting();
     JSContext* cx = aes.cx();
     JS::Rooted<JSObject*> baseGlobal(cx, JS::CurrentGlobalOrNull(cx));
     NS_ENSURE_TRUE(nsContentUtils::GetSecurityManager()->ScriptAllowed(baseGlobal), NS_OK);
 
     JSAddonId* addonId = mCurrentPrototype ? MapURIToAddonID(mCurrentPrototype->GetURI()) : nullptr;
     JS::Rooted<JSObject*> global(cx, xpc::GetAddonScope(cx, baseGlobal, addonId));
     NS_ENSURE_TRUE(global, NS_ERROR_FAILURE);
 
     JS::ExposeObjectToActiveJS(global);
     xpc_UnmarkGrayScript(scriptObject);
     JSAutoCompartment ac(cx, global);
 
     // The script is in the compilation scope. Clone it into the target scope
-    // and execute it.
-    if (!JS::CloneAndExecuteScript(cx, global, scriptObject)) {
-        nsJSUtils::ReportPendingException(cx);
-    }
+    // and execute it. On failure, ~AutoScriptEntry will handle exceptions, so
+    // there is no need to manually check the return value.
+    JS::CloneAndExecuteScript(cx, global, scriptObject);
 
     return NS_OK;
 }
 
 
 nsresult
 XULDocument::CreateElementFromPrototype(nsXULPrototypeElement* aPrototype,
                                         Element** aResult,
--- a/dom/xul/test/chrome.ini
+++ b/dom/xul/test/chrome.ini
@@ -21,9 +21,10 @@ support-files =
 [test_bug445177.xul]
 [test_bug449457.xul]
 [test_bug468176.xul]
 [test_bug497875.xul]
 [test_bug583948.xul]
 [test_bug640158_overlay_persist.xul]
 [test_bug757137.xul]
 [test_bug775972.xul]
+[test_bug1070049_throw_from_script.xul]
 [test_import_xul_to_content.xul]
new file mode 100644
--- /dev/null
+++ b/dom/xul/test/test_bug1070049_throw_from_script.xul
@@ -0,0 +1,41 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1070049
+-->
+<window title="Mozilla Bug 1070049"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+  <!-- test code goes here -->
+  <script type="application/javascript">
+  <![CDATA[
+
+  /** Test for Bug 1070049 **/
+  SimpleTest.waitForExplicitFinish();
+  addLoadEvent(function() {
+    // Prevent the test from failing when the exception hits onerror.
+    SimpleTest.expectUncaughtException();
+
+    // Tell the test to expect exactly one console error with the given parameters,
+    // with SimpleTest.finish as a continuation function.
+    SimpleTest.monitorConsole(SimpleTest.finish, [{errorMessage: new RegExp('flimfniffle')}]);
+
+    // Schedule the console accounting (and continuation) to run next, right
+    // after we throw (below).
+    SimpleTest.executeSoon(SimpleTest.endMonitorConsole);
+
+    // Throw.
+    throw "flimfniffle";
+  });
+  ]]>
+  </script>
+
+  <!-- test results are displayed in the html:body -->
+  <body xmlns="http://www.w3.org/1999/xhtml">
+  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1070049"
+     target="_blank">Mozilla Bug 1070049</a>
+  </body>
+</window>