Bug 1070049 - Remove ReportPendingException from nsProtoImplMethod; r=bholley
authorTerrence Cole <terrence@mozilla.com>
Fri, 14 Nov 2014 10:49:55 -0800
changeset 240645 659549fa7af0f38b1fad6f1e7ec9dc1280946807
parent 240644 57b4489b0a5eb08946edb727273edbc7c98508b0
child 240646 d0b45d3dc7d6f6203457284c1f456bac9395aab2
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1070049
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 1070049 - Remove ReportPendingException from nsProtoImplMethod; r=bholley
dom/xbl/nsXBLProtoImplMethod.cpp
dom/xbl/test/mochitest.ini
dom/xbl/test/test_bug1098628_throw_from_construct.xhtml
--- a/dom/xbl/nsXBLProtoImplMethod.cpp
+++ b/dom/xbl/nsXBLProtoImplMethod.cpp
@@ -290,16 +290,17 @@ nsXBLProtoImplAnonymousMethod::Execute(n
     do_QueryInterface(document->GetInnerWindow());
   if (!global) {
     return NS_OK;
   }
 
   // We are going to run script via JS::Call, so we need a script entry point,
   // but as this is XBL related it does not appear in the HTML spec.
   dom::AutoEntryScript aes(global);
+  aes.TakeOwnershipOfErrorReporting();
   JSContext* cx = aes.cx();
 
   JS::Rooted<JSObject*> globalObject(cx, global->GetGlobalJSObject());
 
   JS::Rooted<JSObject*> scopeObject(cx, xpc::GetScopeForXBLExecution(cx, globalObject, aAddonId));
   NS_ENSURE_TRUE(scopeObject, NS_ERROR_OUT_OF_MEMORY);
 
   JSAutoCompartment ac(cx, scopeObject);
@@ -319,30 +320,22 @@ nsXBLProtoImplAnonymousMethod::Execute(n
     return NS_ERROR_OUT_OF_MEMORY;
 
   // Now call the method
 
   // Check whether script is enabled.
   bool scriptAllowed = nsContentUtils::GetSecurityManager()->
                          ScriptAllowed(js::GetGlobalForObjectCrossCompartment(method));
 
-  bool ok = true;
   if (scriptAllowed) {
     JS::Rooted<JS::Value> retval(cx);
     JS::Rooted<JS::Value> methodVal(cx, JS::ObjectValue(*method));
-    ok = ::JS::Call(cx, scopeChain[0], methodVal, JS::HandleValueArray::empty(), &retval);
-  }
-
-  if (!ok) {
-    // If a constructor or destructor threw an exception, it doesn't stop
-    // anything else.  We just report it.  Note that we need to set aside the
-    // frame chain here, since the constructor invocation is not related to
-    // whatever is on the stack right now, really.
-    nsJSUtils::ReportPendingException(cx);
-    return NS_ERROR_FAILURE;
+    // No need to check the return here as AutoEntryScript has taken ownership
+    // of error reporting.
+    ::JS::Call(cx, scopeChain[0], methodVal, JS::HandleValueArray::empty(), &retval);
   }
 
   return NS_OK;
 }
 
 nsresult
 nsXBLProtoImplAnonymousMethod::Write(nsIObjectOutputStream* aStream,
                                      XBLBindingSerializeDetails aType)
--- a/dom/xbl/test/mochitest.ini
+++ b/dom/xbl/test/mochitest.ini
@@ -37,8 +37,9 @@ skip-if = (buildapp == 'b2g' && toolkit 
 [test_bug639338.xhtml]
 [test_bug790265.xhtml]
 [test_bug821850.html]
 [test_bug844783.html]
 [test_bug872273.xhtml]
 [test_bug946815.html]
 skip-if = toolkit != "gonk"
 [test_bug1086996.xhtml]
+[test_bug1098628_throw_from_construct.xhtml]
new file mode 100644
--- /dev/null
+++ b/dom/xbl/test/test_bug1098628_throw_from_construct.xhtml
@@ -0,0 +1,41 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1098628
+-->
+<head>
+  <title>Test for Bug 1098628</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+  <bindings xmlns="http://www.mozilla.org/xbl">
+    <binding id="test">
+      <implementation>
+        <constructor><![CDATA[
+          throw "flimfniffle";
+        ]]></constructor>
+      </implementation>
+    </binding>
+  </bindings>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1098628">Mozilla Bug 1098628</a>
+<p id="display" style="-moz-binding: url(#test)"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+<![CDATA[
+
+/** Test for Bug 1098628 **/
+SimpleTest.waitForExplicitFinish();
+SimpleTest.expectUncaughtException();
+SimpleTest.monitorConsole(SimpleTest.finish, [{errorMessage: new RegExp('flimfniffle')}]);
+addLoadEvent(function() {
+  SimpleTest.executeSoon(SimpleTest.endMonitorConsole);
+});
+]]>
+</script>
+</pre>
+</body>
+</html>
+