Bug 1234020: Part 2e - [webext] Return promises from the storage API. r=rpl draft
authorKris Maglione <maglione.k@gmail.com>
Fri, 29 Jan 2016 18:59:37 -0800
changeset 328976 aa95c195026cfe0145ed87b3a796c861d40f45f8
parent 328975 52aebf022db6f569a063260a803d060022edd3a0
child 328977 17c48c04f53eee3efea78d6f294530d77c3611e8
push id10445
push usermaglione.k@gmail.com
push dateThu, 04 Feb 2016 21:38:16 +0000
reviewersrpl
bugs1234020
milestone47.0a1
Bug 1234020: Part 2e - [webext] Return promises from the storage API. r=rpl
toolkit/components/extensions/ext-storage.js
--- a/toolkit/components/extensions/ext-storage.js
+++ b/toolkit/components/extensions/ext-storage.js
@@ -3,48 +3,37 @@
 var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 
 XPCOMUtils.defineLazyModuleGetter(this, "ExtensionStorage",
                                   "resource://gre/modules/ExtensionStorage.jsm");
 
 Cu.import("resource://gre/modules/ExtensionUtils.jsm");
 var {
   EventManager,
-  runSafe,
 } = ExtensionUtils;
 
 extensions.registerPrivilegedAPI("storage", (extension, context) => {
   return {
     storage: {
       local: {
         get: function(keys, callback) {
-          ExtensionStorage.get(extension.id, keys).then(result => {
-            runSafe(context, callback, result);
-          });
+          return context.wrapPromise(
+            ExtensionStorage.get(extension.id, keys), callback);
         },
         set: function(items, callback) {
-          ExtensionStorage.set(extension.id, items).then(() => {
-            if (callback) {
-              runSafe(context, callback);
-            }
-          });
+          return context.wrapPromise(
+            ExtensionStorage.set(extension.id, items), callback);
         },
         remove: function(items, callback) {
-          ExtensionStorage.remove(extension.id, items).then(() => {
-            if (callback) {
-              runSafe(context, callback);
-            }
-          });
+          return context.wrapPromise(
+            ExtensionStorage.remove(extension.id, items), callback);
         },
         clear: function(callback) {
-          ExtensionStorage.clear(extension.id).then(() => {
-            if (callback) {
-              runSafe(context, callback);
-            }
-          });
+          return context.wrapPromise(
+            ExtensionStorage.clear(extension.id), callback);
         },
       },
 
       onChanged: new EventManager(context, "storage.local.onChanged", fire => {
         let listener = changes => {
           fire(changes, "local");
         };