Bug 1287007 - Do not neuter error messages from the same principal r=billm
authorRob Wu <rob@robwu.nl>
Mon, 05 Sep 2016 17:04:28 -0700
changeset 428704 d6ac05fb1b56cfc90ba785a9c65095bf71cf6dc7
parent 428703 5df860aa9c9ca508841e1a0c7d96ab389fda8ea3
child 428705 642f1b1afa902ddf5f9043bcd799feede7e67396
push id33405
push userbcampen@mozilla.com
push dateMon, 24 Oct 2016 15:32:53 +0000
reviewersbillm
bugs1287007
milestone52.0a1
Bug 1287007 - Do not neuter error messages from the same principal r=billm 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
@@ -360,21 +360,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