Bug 1348885 - Prevent throwing on dead wrapper when processing stacks of error from nuked globals. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 23 Mar 2017 18:53:57 +0100
changeset 503879 48fb683ebb83fe1b78fee13af494695e8560d53a
parent 503825 439ee2e4fc4ed4a82102608639d9751e376d5536
child 550529 1469e5e1089e122fc354d02286cca61dff00208d
push id50684
push userbmo:poirot.alex@gmail.com
push dateThu, 23 Mar 2017 17:55:15 +0000
reviewersjryans
bugs1348885
milestone55.0a1
Bug 1348885 - Prevent throwing on dead wrapper when processing stacks of error from nuked globals. r=jryans MozReview-Commit-ID: gdFNYNzXLz
devtools/client/webconsole/test/browser_console.js
devtools/server/actors/webconsole.js
--- a/devtools/client/webconsole/test/browser_console.js
+++ b/devtools/client/webconsole/test/browser_console.js
@@ -45,16 +45,27 @@ function consoleOpened(hud) {
 
   // Add a message from a chrome window.
   hud.iframeWindow.console.log("bug587757a");
 
   // Check Cu.reportError stack.
   // Use another js script to not depend on the test file line numbers.
   Services.scriptloader.loadSubScript(TEST_FILE, hud.iframeWindow);
 
+  // Bug 1348885: test that error from nuked globals do not throw
+  let sandbox = new Cu.Sandbox(null, {
+    wantComponents: false,
+    wantGlobalProperties: ["URL", "URLSearchParams"],
+  });
+  let error = Cu.evalInSandbox(`
+    new Error("1348885");
+  `, sandbox);
+  Cu.reportError(error);
+  Cu.nukeSandbox(sandbox);
+
   // Add a message from a content window.
   content.console.log("bug587757b");
 
   // Test eval.
   hud.jsterm.execute("document.location.href");
 
   // Check for network requests.
   let xhr = new XMLHttpRequest();
@@ -95,16 +106,22 @@ function consoleOpened(hud) {
           line: 4,
         },
         // Ignore the rest of the stack,
         // just assert Cu.reportError call site
         // and consoleOpened call
         ]
       },
       {
+        name: "Error from nuked global works",
+        text: "1348885",
+        category: CATEGORY_JS,
+        severity: SEVERITY_ERROR,
+      },
+      {
         name: "content window console.log() is displayed",
         text: "bug587757b",
         category: CATEGORY_WEBDEV,
         severity: SEVERITY_LOG,
       },
       {
         name: "jsterm eval result",
         text: "browser.xul",
--- a/devtools/server/actors/webconsole.js
+++ b/devtools/server/actors/webconsole.js
@@ -1507,17 +1507,19 @@ WebConsoleActor.prototype =
    *        The page error we need to send to the client.
    * @return object
    *         The object you can send to the remote client.
    */
   preparePageErrorForRemote: function WCA_preparePageErrorForRemote(aPageError)
   {
     let stack = null;
     // Convert stack objects to the JSON attributes expected by client code
-    if (aPageError.stack) {
+    // Bug 1348885: If the global from which this error came from has been
+    // nuked, stack is going to be a dead wrapper.
+    if (aPageError.stack && !Cu.isDeadWrapper(aPageError.stack)) {
       stack = [];
       let s = aPageError.stack;
       while (s !== null) {
         stack.push({
           filename: s.source,
           lineNumber: s.line,
           columnNumber: s.column,
           functionName: s.functionDisplayName