Bug 1287007 - Fix some flaws in ProxyAPIImplementation r=billm
authorRob Wu <rob@robwu.nl>
Thu, 01 Sep 2016 21:10:18 -0700
changeset 428694 5e6462c7563d934c4bc780a567663bba4d8f0f47
parent 428693 47efa3e76f692a661cc2edfe0ac8e3ebf38550ac
child 428695 fbbeab9bd95bca3c7f97e3cadebd42d93c7610bb
push id33405
push userbcampen@mozilla.com
push dateMon, 24 Oct 2016 15:32:53 +0000
reviewersbillm
bugs1287007
milestone52.0a1
Bug 1287007 - Fix some flaws in ProxyAPIImplementation r=billm - removeListener: There is no set.remove, use set.delete. - Async callbacks: Do not unconditionally turn the result in a SpreadArgs because it causes the result to unconditionally be wrapped in an array (+test). MozReview-Commit-ID: LqwtBsHWJJr
toolkit/components/extensions/ExtensionUtils.jsm
toolkit/components/extensions/test/mochitest/test_ext_storage_content.html
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -452,16 +452,18 @@ class BaseContext {
     } else {
       return new this.cloneScope.Promise((resolve, reject) => {
         promise.then(
           value => {
             if (this.unloaded) {
               dump(`Promise resolved after context unloaded\n`);
             } else if (!this.active) {
               dump(`Promise resolved while context is inactive\n`);
+            } else if (value instanceof SpreadArgs) {
+              runSafe(resolve, value.length == 1 ? value[0] : value);
             } else {
               runSafe(resolve, value);
             }
           },
           value => {
             if (this.unloaded) {
               dump(`Promise rejected after context unloaded: ${value && value.message}\n`);
             } else if (!this.active) {
@@ -1739,17 +1741,17 @@ class ProxyAPIImplementation extends Sch
     }
   }
 
   removeListener(listener) {
     let set = this.childApiManager.listeners.get(this.path);
     if (!set) {
       return;
     }
-    set.remove(listener);
+    set.delete(listener);
 
     if (set.size == 0) {
       this.childApiManager.messageManager.sendAsyncMessage("API:RemoveListener", {
         childId: this.childApiManager.id,
         path: this.path,
       });
     }
   }
--- a/toolkit/components/extensions/test/mochitest/test_ext_storage_content.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_storage_content.html
@@ -45,16 +45,19 @@ function contentScript() {
     }).then(data => {
       browser.test.assertEq(data[prop], value, "string getter worked for " + prop);
       return get([prop]);
     }).then(data => {
       browser.test.assertEq(data[prop], value, "array getter worked for " + prop);
       return get({[prop]: undefined});
     }).then(data => {
       browser.test.assertEq(data[prop], value, "object getter worked for " + prop);
+      return browser.storage.local.get(prop).then(data => {
+        browser.test.assertEq(data[prop], value, "promise getter worked for " + prop);
+      });
     });
   }
 
   let globalChanges = {};
 
   browser.storage.onChanged.addListener((changes, storage) => {
     browser.test.assertEq(storage, "local", "storage is local");
     Object.assign(globalChanges, changes);