Bug 1287007 - Do not neuter error messages from the same principal draft
authorRob Wu <rob@robwu.nl>
Mon, 05 Sep 2016 17:04:28 -0700
changeset 411552 c8204bd45b6f9e48bfe27ba6f0464ba3c2e8fb65
parent 411551 bb36a764a97dec24b28ca6cbec11e817e797bda8
child 411553 a63f1b6ad722cd2c3e2834dc52e280c3be024e7a
push id28922
push userbmo:rob@robwu.nl
push dateThu, 08 Sep 2016 08:44:00 +0000
bugs1287007
milestone51.0a1
Bug 1287007 - Do not neuter error messages from the same principal With an upcoming change that introduces another ProxyContext, errors from a different scope may bubble up. These messages should be reported, not replaced with "An unexpected error occurred". MozReview-Commit-ID: ByUktVkhDyx
toolkit/components/extensions/ExtensionUtils.jsm
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -344,21 +344,27 @@ class BaseContext {
    *
    * @param {Error|object} error
    * @returns {Error}
    */
   normalizeError(error) {
     if (error instanceof this.cloneScope.Error) {
       return error;
     }
-    if (!instanceOf(error, "Object")) {
+    let message;
+    if (instanceOf(error, "Object")) {
+      message = error.message;
+    } else if (typeof error == "object" &&
+        this.principal.subsumes(Cu.getObjectPrincipal(error))) {
+      message = error.message;
+    } else {
       Cu.reportError(error);
-      error = {message: "An unexpected error occurred"};
     }
-    return new this.cloneScope.Error(error.message);
+    message = message || "An unexpected error occurred";
+    return new this.cloneScope.Error(message);
   }
 
   /**
    * Sets the value of `.lastError` to `error`, calls the given
    * callback, and reports an error if the value has not been checked
    * when the callback returns.
    *
    * @param {object} error An object with a `message` property. May