Bug 1128760 - Part 1: Disable onerror hooking in chrome context. r=jgriffin
authorEric Rahm <erahm@mozilla.com>
Sat, 07 Feb 2015 12:05:27 -0800
changeset 241832 a19cb997c0268d3cc1382b65214233d5976b3e50
parent 241831 b7a61f34185e4128b5155cc3eedfcc7cf6a90f65
child 241833 075d31f8da0e1c5c274b7d7684cf16333738dc21
push id624
push userdburns@mozilla.com
push dateTue, 10 Feb 2015 13:30:25 +0000
reviewersjgriffin
bugs1128760
milestone38.0a1
Bug 1128760 - Part 1: Disable onerror hooking in chrome context. r=jgriffin
testing/marionette/client/marionette/tests/unit/test_execute_async_script.py
testing/marionette/marionette-server.js
--- a/testing/marionette/client/marionette/tests/unit/test_execute_async_script.py
+++ b/testing/marionette/client/marionette/tests/unit/test_execute_async_script.py
@@ -119,8 +119,17 @@ class TestExecuteAsyncChrome(TestExecute
     def test_execute_async_unload(self):
         pass
 
     def test_execute_permission(self):
         self.assertEqual(5, self.marionette.execute_async_script("""
 var c = Components.classes;
 marionetteScriptFinished(5);
 """))
+
+    def test_execute_async_js_exception(self):
+        # Javascript exceptions are not propagated in chrome code
+        self.marionette.set_script_timeout(200)
+        self.assertRaises(ScriptTimeoutException,
+            self.marionette.execute_async_script, """
+            var callback = arguments[arguments.length - 1];
+            setTimeout("callback(foo())", 50);
+            """)
--- a/testing/marionette/marionette-server.js
+++ b/testing/marionette/marionette-server.js
@@ -1123,20 +1123,26 @@ MarionetteServerConnection.prototype = {
         }
       }
 
       if (that.inactivityTimer != null) {
         that.inactivityTimer.cancel();
       }
     }
 
-    curWindow.onerror = function (errorMsg, url, lineNumber) {
-      chromeAsyncReturnFunc(errorMsg + " at: " + url + " line: " + lineNumber, 17);
-      return true;
-    };
+    // NB: curWindow.onerror is not hooked by default due to the inability to
+    //     differentiate content exceptions from chrome exceptions. See bug
+    //     1128760 for more details. A 'debug_script' flag can be set to
+    //     reenable onerror hooking to help debug test scripts.
+    if (aRequest.parameters.debug_script) {
+      curWindow.onerror = function (errorMsg, url, lineNumber) {
+        chromeAsyncReturnFunc(errorMsg + " at: " + url + " line: " + lineNumber, 17);
+        return true;
+      };
+    }
 
     function chromeAsyncFinish() {
       chromeAsyncReturnFunc(that.sandbox.generate_results(), 0);
     }
 
     if (!this.sandbox || newSandbox) {
       let marionette = new Marionette(this, curWindow, "chrome",
                                       this.marionetteLog,