DELETE: 1 patches - 939636-dom
authorNikhil Marathe <nsm.nikhil@gmail.com>
Wed, 23 Jul 2014 17:33:26 -0700
changeset 1110 4438fd9f3ae866a06620808ce596d1b50a330ead
parent 1109 f399569a6fddf0a9ed8793676892322e6c5e3c34
child 1111 6b363bfd74f3691455865bdd60cca27746498046
push id32
push usernsm.nikhil@gmail.com
push dateThu, 24 Jul 2014 00:32:46 +0000
bugs939636
DELETE: 1 patches - 939636-dom DELETE: 939636-dom qparent: 666e5e6b3abf qtip: 666e5e6b3abf top: (none)
939636-dom
series
deleted file mode 100644
--- a/939636-dom
+++ /dev/null
@@ -1,1648 +0,0 @@
-# HG changeset patch
-# Parent 00380e322a082f4ee31cac7316d76bd6c5615b82
-# User Nikhil Marathe <nsm.nikhil@gmail.com>
-Bug 939636 - Remove Promise.jsm from dom/. r=?
-
-diff --git a/dom/browser-element/mochitest/browserElementTestHelpers.js b/dom/browser-element/mochitest/browserElementTestHelpers.js
---- a/dom/browser-element/mochitest/browserElementTestHelpers.js
-+++ b/dom/browser-element/mochitest/browserElementTestHelpers.js
-@@ -74,17 +74,17 @@ const browserElementTestHelpers = {
-     SpecialPowers.addPermission("browser", true, url);
-     this.tempPermissions.push(url);
-   },
- 
-   _observers: [],
- 
-   // This function is a wrapper which lets you register an observer to one of
-   // the process priority manager's test-only topics.  observerFn should be a
--  // function which takes (subject, topic, data).
-+  // function which takes (data).
-   //
-   // We'll clean up any observers you add at the end of the test.
-   addProcessPriorityObserver: function(processPriorityTopic, observerFn) {
-     var topic = "process-priority-manager:TEST-ONLY:" + processPriorityTopic;
- 
-     // SpecialPowers appears to require that the observer be an object, not a
-     // function.
-     var observer = {
-@@ -111,36 +111,26 @@ const browserElementTestHelpers = {
-   'emptyPage2': 'http://example.org' + _getPath() + '/file_empty.html',
-   'emptyPage3': 'http://test1.example.org' + _getPath() + '/file_empty.html',
-   'focusPage': 'http://example.org' + _getPath() + '/file_focus.html',
- };
- 
- // Returns a promise which is resolved when a subprocess is created.  The
- // argument to resolve() is the childID of the subprocess.
- function expectProcessCreated() {
--  var deferred = Promise.defer();
-+  var promise = new Promise(function(resolve) {
-+    browserElementTestHelpers.addProcessPriorityObserver("process-created",
-+                                                         resolve);
-+  });
- 
--  var observed = false;
--  browserElementTestHelpers.addProcessPriorityObserver(
--    "process-created",
--    function(subject, topic, data) {
--      // Don't run this observer twice, so we don't ok(true) twice.  (It's fine
--      // to resolve a promise twice; the second resolve() call does nothing.)
--      if (observed) {
--        return;
--      }
--      observed = true;
--
--      var childID = parseInt(data);
--      ok(true, 'Got new process, id=' + childID);
--      deferred.resolve(childID);
--    }
--  );
--
--  return deferred.promise;
-+  return promise.then(function(data) {
-+    var childID = parseInt(data);
-+    ok(true, 'Got new process, id=' + childID);
-+    return childID;
-+  });
- }
- 
- // Just like expectProcessCreated(), except we'll call ok(false) if a second
- // process is created.
- function expectOnlyOneProcessCreated() {
-   var p = expectProcessCreated();
-   p.then(function() {
-     expectProcessCreated().then(function(childID) {
-@@ -160,23 +150,25 @@ function expectOnlyOneProcessCreated() {
- 
- function expectPriorityChange(childID, expectedPriority,
-                               /* optional */ expectedCPUPriority) {
-   var deferred = Promise.defer();
- 
-   var observed = false;
-   browserElementTestHelpers.addProcessPriorityObserver(
-     'process-priority-set',
--    function(subject, topic, data) {
-+    function(data) {
-       if (observed) {
-         return;
-       }
- 
-       [id, priority, cpuPriority] = data.split(":");
-       if (id != childID) {
-+      // FIXME(nsm) how do you capture the 'promise is never resolved or rejected' in DOM
-+      // Promises?
-         return;
-       }
- 
-       // Make sure we run the is() calls in this observer only once, otherwise
-       // we'll expect /every/ priority change to match expectedPriority.
-       observed = true;
- 
-       is(priority, expectedPriority,
-@@ -205,21 +197,20 @@ function expectPriorityChange(childID, e
- // process childID changes its priority.  We resolve if the backgroundLRU
- // matches expectedBackgroundLRU and we reject otherwise.
- 
- function expectPriorityWithBackgroundLRUSet(childID, expectedBackgroundLRU) {
-   var deferred = Promise.defer();
- 
-   browserElementTestHelpers.addProcessPriorityObserver(
-     'process-priority-with-background-LRU-set',
--    function(subject, topic, data) {
--
--      dump("browserElementTestHelpers got notify: topic "+ topic + ", data " + data +"\n");
-+    function(data) {
-       [id, priority, cpuPriority, backgroundLRU] = data.split(":");
-       if (id != childID) {
-+      //FIXME(nsm): Here too
-         dump("id(" + id + ") != childID(" + childID + ")\n");
-         return;
-       }
- 
-       is(backgroundLRU, expectedBackgroundLRU,
-          'Expected backgroundLRU ' + backgroundLRU + ' of childID ' + childID +
-          ' to change to ' + expectedBackgroundLRU);
- 
-@@ -232,22 +223,22 @@ function expectPriorityWithBackgroundLRU
-   );
- 
-   return deferred.promise;
- }
- 
- // Returns a promise which is resolved the first time the given iframe fires
- // the mozbrowser##eventName event.
- function expectMozbrowserEvent(iframe, eventName) {
--  var deferred = Promise.defer();
--  iframe.addEventListener('mozbrowser' + eventName, function handler(e) {
--    iframe.removeEventListener('mozbrowser' + eventName, handler);
--    deferred.resolve(e);
-+  return new Promise(function(resolve) {
-+    iframe.addEventListener('mozbrowser' + eventName, function handler(e) {
-+      iframe.removeEventListener('mozbrowser' + eventName, handler);
-+      resolve(e);
-+    });
-   });
--  return deferred.promise;
- }
- 
- // Set some prefs:
- //
- //  * browser.pagethumbnails.capturing_disabled: true
- //
- //    Disable tab view; it seriously messes us up.
- //
-@@ -296,281 +287,8 @@ addEventListener('unload', function() {
-   browserElementTestHelpers.cleanUp();
- });
- 
- // Wait for the load event before unlocking the test-ready event.
- browserElementTestHelpers.lockTestReady();
- addEventListener('load', function() {
-   SimpleTest.executeSoon(browserElementTestHelpers.unlockTestReady.bind(browserElementTestHelpers));
- });
--
--//////////////////////////////////
--// promise.js from the addon SDK with some modifications to the module
--// boilerplate.
--//////////////////////////////////
--
--;(function(id, factory) { // Module boilerplate :(
--    var globals = this;
--    factory(function require(id) {
--      return globals[id];
--    }, (globals[id] = {}), { uri: document.location.href + '#' + id, id: id });
--}).call(this, 'Promise', function Promise(require, exports, module) {
--
--'use strict';
--
--module.metadata = {
--  "stability": "unstable"
--};
--
--/**
-- * Internal utility: Wraps given `value` into simplified promise, successfully
-- * fulfilled to a given `value`. Note the result is not a complete promise
-- * implementation, as its method `then` does not returns anything.
-- */
--function fulfilled(value) {
--  return { then: function then(fulfill) { fulfill(value); } };
--}
--
--/**
-- * Internal utility: Wraps given input into simplified promise, pre-rejected
-- * with a given `reason`. Note the result is not a complete promise
-- * implementation, as its method `then` does not returns anything.
-- */
--function rejected(reason) {
--  return { then: function then(fulfill, reject) { reject(reason); } };
--}
--
--/**
-- * Internal utility: Returns `true` if given `value` is a promise. Value is
-- * assumed to be a promise if it implements method `then`.
-- */
--function isPromise(value) {
--  return value && typeof(value.then) === 'function';
--}
--
--/**
-- * Creates deferred object containing fresh promise & methods to either resolve
-- * or reject it. The result is an object with the following properties:
-- * - `promise` Eventual value representation implementing CommonJS [Promises/A]
-- *   (http://wiki.commonjs.org/wiki/Promises/A) API.
-- * - `resolve` Single shot function that resolves enclosed `promise` with a
-- *   given `value`.
-- * - `reject` Single shot function that rejects enclosed `promise` with a given
-- *   `reason`.
-- *
-- * An optional `prototype` argument is used as a prototype of the returned
-- * `promise` allowing one to implement additional API. If prototype is not
-- * passed then it falls back to `Object.prototype`.
-- *
-- *  ## Example
-- *
-- *  function fetchURI(uri, type) {
-- *    var deferred = defer();
-- *    var request = new XMLHttpRequest();
-- *    request.open("GET", uri, true);
-- *    request.responseType = type;
-- *    request.onload = function onload() {
-- *      deferred.resolve(request.response);
-- *    }
-- *    request.onerror = function(event) {
-- *     deferred.reject(event);
-- *    }
-- *    request.send();
-- *
-- *    return deferred.promise;
-- *  }
-- */
--function defer(prototype) {
--  // Define FIFO queue of observer pairs. Once promise is resolved & all queued
--  // observers are forwarded to `result` and variable is set to `null`.
--  var observers = [];
--
--  // Promise `result`, which will be assigned a resolution value once promise
--  // is resolved. Note that result will always be assigned promise (or alike)
--  // object to take care of propagation through promise chains. If result is
--  // `null` promise is not resolved yet.
--  var result = null;
--
--  prototype = (prototype || prototype === null) ? prototype : Object.prototype;
--
--  // Create an object implementing promise API.
--  var promise = Object.create(prototype, {
--    then: { value: function then(onFulfill, onError) {
--      var deferred = defer(prototype);
--
--      function resolve(value) {
--        // If `onFulfill` handler is provided resolve `deferred.promise` with
--        // result of invoking it with a resolution value. If handler is not
--        // provided propagate value through.
--        try {
--          deferred.resolve(onFulfill ? onFulfill(value) : value);
--        }
--        // `onFulfill` may throw exception in which case resulting promise
--        // is rejected with thrown exception.
--        catch(error) {
--          if (exports._reportErrors && typeof(console) === 'object')
--            console.error(error);
--          // Note: Following is equivalent of `deferred.reject(error)`,
--          // we use this shortcut to reduce a stack.
--          deferred.resolve(rejected(error));
--        }
--      }
--
--      function reject(reason) {
--        try {
--          if (onError) deferred.resolve(onError(reason));
--          else deferred.resolve(rejected(reason));
--        }
--        catch(error) {
--          if (exports._reportErrors && typeof(console) === 'object')
--            console.error(error)
--          deferred.resolve(rejected(error));
--        }
--      }
--
--      // If enclosed promise (`this.promise`) observers queue is still alive
--      // enqueue a new observer pair into it. Note that this does not
--      // necessary means that promise is pending, it may already be resolved,
--      // but we still have to queue observers to guarantee an order of
--      // propagation.
--      if (observers) {
--        observers.push({ resolve: resolve, reject: reject });
--      }
--      // Otherwise just forward observer pair right to a `result` promise.
--      else {
--        result.then(resolve, reject);
--      }
--
--      return deferred.promise;
--    }}
--  })
--
--  var deferred = {
--    promise: promise,
--    /**
--     * Resolves associated `promise` to a given `value`, unless it's already
--     * resolved or rejected. Note that resolved promise is not necessary a
--     * successfully fulfilled. Promise may be resolved with a promise `value`
--     * in which case `value` promise's fulfillment / rejection will propagate
--     * up to a promise resolved with `value`.
--     */
--    resolve: function resolve(value) {
--      if (!result) {
--        // Store resolution `value` in a `result` as a promise, so that all
--        // the subsequent handlers can be simply forwarded to it. Since
--        // `result` will be a promise all the value / error propagation will
--        // be uniformly taken care of.
--        result = isPromise(value) ? value : fulfilled(value);
--
--        // Forward already registered observers to a `result` promise in the
--        // order they were registered. Note that we intentionally dequeue
--        // observer at a time until queue is exhausted. This makes sure that
--        // handlers registered as side effect of observer forwarding are
--        // queued instead of being invoked immediately, guaranteeing FIFO
--        // order.
--        while (observers.length) {
--          var observer = observers.shift();
--          result.then(observer.resolve, observer.reject);
--        }
--
--        // Once `observers` queue is exhausted we `null`-ify it, so that
--        // new handlers are forwarded straight to the `result`.
--        observers = null;
--      }
--    },
--    /**
--     * Rejects associated `promise` with a given `reason`, unless it's already
--     * resolved / rejected. This is just a (better performing) convenience
--     * shortcut for `deferred.resolve(reject(reason))`.
--     */
--    reject: function reject(reason) {
--      // Note that if promise is resolved that does not necessary means that it
--      // is successfully fulfilled. Resolution value may be a promise in which
--      // case its result propagates. In other words if promise `a` is resolved
--      // with promise `b`, `a` is either fulfilled or rejected depending
--      // on weather `b` is fulfilled or rejected. Here `deferred.promise` is
--      // resolved with a promise pre-rejected with a given `reason`, there for
--      // `deferred.promise` is rejected with a given `reason`. This may feel
--      // little awkward first, but doing it this way greatly simplifies
--      // propagation through promise chains.
--      deferred.resolve(rejected(reason));
--    }
--  };
--
--  return deferred;
--}
--exports.defer = defer;
--
--/**
-- * Returns a promise resolved to a given `value`. Optionally a second
-- * `prototype` argument may be provided to be used as a prototype for the
-- * returned promise.
-- */
--function resolve(value, prototype) {
--  var deferred = defer(prototype);
--  deferred.resolve(value);
--  return deferred.promise;
--}
--exports.resolve = resolve;
--
--/**
-- * Returns a promise rejected with a given `reason`. Optionally a second
-- * `prototype` argument may be provided to be used as a prototype for the
-- * returned promise.
-- */
--function reject(reason, prototype) {
--  var deferred = defer(prototype);
--  deferred.reject(reason);
--  return deferred.promise;
--}
--exports.reject = reject;
--
--var promised = (function() {
--  // Note: Define shortcuts and utility functions here in order to avoid
--  // slower property accesses and unnecessary closure creations on each
--  // call of this popular function.
--
--  var call = Function.call;
--  var concat = Array.prototype.concat;
--
--  // Utility function that does following:
--  // execute([ f, self, args...]) => f.apply(self, args)
--  function execute(args) { return call.apply(call, args) }
--
--  // Utility function that takes promise of `a` array and maybe promise `b`
--  // as arguments and returns promise for `a.concat(b)`.
--  function promisedConcat(promises, unknown) {
--    return promises.then(function(values) {
--      return resolve(unknown).then(function(value) {
--        return values.concat([ value ])
--      });
--    });
--  }
--
--  return function promised(f, prototype) {
--    /**
--    Returns a wrapped `f`, which when called returns a promise that resolves to
--    `f(...)` passing all the given arguments to it, which by the way may be
--    promises. Optionally second `prototype` argument may be provided to be used
--    a prototype for a returned promise.
--
--    ## Example
--
--    var promise = promised(Array)(1, promise(2), promise(3))
--    promise.then(console.log) // => [ 1, 2, 3 ]
--    **/
--
--    return function promised() {
--      // create array of [ f, this, args... ]
--      return concat.apply([ f, this ], arguments).
--        // reduce it via `promisedConcat` to get promised array of fulfillments
--        reduce(promisedConcat, resolve([], prototype)).
--        // finally map that to promise of `f.apply(this, args...)`
--        then(execute);
--    }
--  }
--})();
--exports.promised = promised;
--
--var all = promised(Array);
--exports.all = all;
--
--});
-diff --git a/dom/mobilemessage/tests/marionette/head.js b/dom/mobilemessage/tests/marionette/head.js
---- a/dom/mobilemessage/tests/marionette/head.js
-+++ b/dom/mobilemessage/tests/marionette/head.js
-@@ -1,52 +1,51 @@
- /* Any copyright is dedicated to the Public Domain.
-  * http://creativecommons.org/publicdomain/zero/1.0/ */
- 
- const {Cc: Cc, Ci: Ci, Cr: Cr, Cu: Cu} = SpecialPowers;
- 
--let Promise = Cu.import("resource://gre/modules/Promise.jsm").Promise;
--
- /* Push required permissions and test if |navigator.mozMobileMessage| exists.
-  * Resolve if it does, reject otherwise.
-  *
-  * Forfill params:
-  *   manager -- an reference to navigator.mozMobileMessage.
-  *
-  * Reject params: (none)
-  *
-  * @return A deferred promise.
-  */
- let manager;
- function ensureMobileMessage() {
--  let deferred = Promise.defer();
--
-   let permissions = [{
-     "type": "sms",
-     "allow": 1,
-     "context": document,
-   }];
--  SpecialPowers.pushPermissions(permissions, function() {
-+
-+  let promise = new Promise(function(resolve) {
-+    SpecialPowers.pushPermissions(permissions, resolve);
-+  });
-+
-+  return promise.then(function() {
-     ok(true, "permissions pushed: " + JSON.stringify(permissions));
- 
-     manager = window.navigator.mozMobileMessage;
-     if (manager) {
-       log("navigator.mozMobileMessage is instance of " + manager.constructor);
-     } else {
-       log("navigator.mozMobileMessage is undefined.");
-     }
- 
-     if (manager instanceof MozMobileMessageManager) {
--      deferred.resolve(manager);
-+      return manager;
-     } else {
--      deferred.reject();
-+      return Promise.reject();
-     }
-   });
--
--  return deferred.promise;
- }
- 
- /* Send a SMS message to a single receiver.  Resolve if it succeeds, reject
-  * otherwise.
-  *
-  * Forfill params:
-  *   message -- the sent SmsMessage.
-  *
-@@ -54,55 +53,51 @@ function ensureMobileMessage() {
-  *   error -- a DOMError.
-  *
-  * @param aReceiver the address of the receiver.
-  * @param aText the text body of the message.
-  *
-  * @return A deferred promise.
-  */
- function sendSmsWithSuccess(aReceiver, aText) {
--  let deferred = Promise.defer();
--
--  let request = manager.send(aReceiver, aText);
--  request.onsuccess = function(event) {
--    deferred.resolve(event.target.result);
--  };
--  request.onerror = function(event) {
--    deferred.reject(event.target.error);
--  };
--
--  return deferred.promise;
-+  return new Promise(function(resolve, reject) {
-+    let request = manager.send(aReceiver, aText);
-+    request.onsuccess = function(event) {
-+      resolve(event.target.result);
-+    };
-+    request.onerror = function(event) {
-+      reject(event.target.error);
-+    };
-+  });
- }
- 
- /* Send a MMS message with specified parameters.  Resolve if it fails, reject
-  * otherwise.
-  *
-  * Forfill params:
-  *   message -- the failed MmsMessage
-  *
-  * Reject params: (none)
-  *
-  * @param aMmsParameters a MmsParameters instance.
-  *
-  * @return A deferred promise.
-  */
- function sendMmsWithFailure(aMmsParameters) {
--  let deferred = Promise.defer();
-+  return new Promise(function(resolve, reject) {
-+    manager.onfailed = function(event) {
-+      manager.onfailed = null;
-+      resolve(event.message);
-+    };
- 
--  manager.onfailed = function(event) {
--    manager.onfailed = null;
--    deferred.resolve(event.message);
--  };
--
--  let request = manager.sendMMS(aMmsParameters);
--  request.onsuccess = function(event) {
--    deferred.reject();
--  };
--
--  return deferred.promise;
-+    let request = manager.sendMMS(aMmsParameters);
-+    request.onsuccess = function(event) {
-+      reject();
-+    };
-+  });
- }
- 
- /* Retrieve messages from database.
-  *
-  * Forfill params:
-  *   messages -- an array of {Sms,Mms}Message instances.
-  *
-  * Reject params:
-@@ -110,35 +105,33 @@ function sendMmsWithFailure(aMmsParamete
-  *
-  * @param aFilter an optional MozSmsFilter instance.
-  * @param aReverse a boolean value indicating whether the order of the messages
-  *                 should be reversed.
-  *
-  * @return A deferred promise.
-  */
- function getMessages(aFilter, aReverse) {
--  let deferred = Promise.defer();
--
-   if (!aFilter) {
-     aFilter = new MozSmsFilter;
-   }
-   let messages = [];
--  let cursor = manager.getMessages(aFilter, aReverse || false);
--  cursor.onsuccess = function(aEvent) {
--    if (cursor.result) {
--      messages.push(cursor.result);
--      cursor.continue();
--      return;
--    }
-+  return new Promise(function(resolve, reject) {
-+    let cursor = manager.getMessages(aFilter, aReverse || false);
-+    cursor.onsuccess = function(aEvent) {
-+      if (cursor.result) {
-+        messages.push(cursor.result);
-+        cursor.continue();
-+        return;
-+      }
- 
--    deferred.resolve(messages);
--  };
--  cursor.onerror = deferred.reject.bind(deferred);
--
--  return deferred.promise;
-+      resolve(messages);
-+    };
-+    cursor.onerror = reject;
-+  });
- }
- 
- /* Retrieve all messages from database.
-  *
-  * Forfill params:
-  *   messages -- an array of {Sms,Mms}Message instances.
-  *
-  * Reject params:
-@@ -156,32 +149,30 @@ function getAllMessages() {
-  *   threads -- an array of MozMobileMessageThread instances.
-  *
-  * Reject params:
-  *   event -- a DOMEvent
-  *
-  * @return A deferred promise.
-  */
- function getAllThreads() {
--  let deferred = Promise.defer();
-+  let threads = [];
-+  return new Promise(function(resolve, reject) {
-+    let cursor = manager.getThreads();
-+    cursor.onsuccess = function(aEvent) {
-+      if (cursor.result) {
-+        threads.push(cursor.result);
-+        cursor.continue();
-+        return;
-+      }
- 
--  let threads = [];
--  let cursor = manager.getThreads();
--  cursor.onsuccess = function(aEvent) {
--    if (cursor.result) {
--      threads.push(cursor.result);
--      cursor.continue();
--      return;
--    }
--
--    deferred.resolve(threads);
--  };
--  cursor.onerror = deferred.reject.bind(deferred);
--
--  return deferred.promise;
-+      resolve(threads);
-+    };
-+    cursor.onerror = reject;
-+  });
- }
- 
- /* Retrieve a single specified thread from database.
-  *
-  * Forfill params:
-  *   thread -- a MozMobileMessageThread instance.
-  *
-  * Reject params:
-@@ -218,25 +209,23 @@ function getThreadById(aThreadId) {
-  * @return An empty array if nothing to be deleted; otherwise, a deferred promise.
-  */
- function deleteMessagesById(aMessageIds) {
-   if (!aMessageIds.length) {
-     ok(true, "no message to be deleted");
-     return [];
-   }
- 
--  let deferred = Promise.defer();
--
--  let request = manager.delete(aMessageIds);
--  request.onsuccess = function(event) {
--    deferred.resolve(event.target.result);
--  };
--  request.onerror = deferred.reject.bind(deferred);
--
--  return deferred.promise;
-+  return new Promise(function(resolve, reject) {
-+    let request = manager.delete(aMessageIds);
-+    request.onsuccess = function(event) {
-+      resolve(event.target.result);
-+    };
-+    request.onerror = reject;
-+  });
- }
- 
- /* Delete messages specified from database.
-  *
-  * Forfill params:
-  *   result -- an array of boolean values indicating whether delesion was
-  *             actually performed on the message record with corresponding id.
-  *
-diff --git a/dom/mobilemessage/tests/marionette/test_dsds_default_service_id.js b/dom/mobilemessage/tests/marionette/test_dsds_default_service_id.js
---- a/dom/mobilemessage/tests/marionette/test_dsds_default_service_id.js
-+++ b/dom/mobilemessage/tests/marionette/test_dsds_default_service_id.js
-@@ -1,130 +1,87 @@
- /* Any copyright is dedicated to the Public Domain.
-  * http://creativecommons.org/publicdomain/zero/1.0/ */
- 
- MARIONETTE_TIMEOUT = 60000;
- MARIONETTE_CONTEXT = "chrome";
- 
--Cu.import("resource://gre/modules/Promise.jsm");
--
- const MMS_SERVICE_CONTRACTID = "@mozilla.org/mms/mmsservice;1";
- const SMS_SERVICE_CONTRACTID = "@mozilla.org/sms/smsservice;1";
- 
- const PREF_RIL_NUM_RADIO_INTERFACES = "ril.numRadioInterfaces";
- const PREF_MMS_DEFAULT_SERVICE_ID = "dom.mms.defaultServiceId";
- const PREF_SMS_DEFAULT_SERVICE_ID = "dom.sms.defaultServiceId";
- 
--function setPrefAndVerify(prefKey, setVal, service, attrName, expectedVal, deferred) {
-+function setPrefAndVerify(prefKey, setVal, service, attrName, expectedVal) {
-   log("  Set '" + prefKey + "' to " + setVal);
-   Services.prefs.setIntPref(prefKey, setVal);
-   let prefVal = Services.prefs.getIntPref(prefKey);
-   is(prefVal, setVal, "'" + prefKey + "' set to " + setVal);
- 
--  window.setTimeout(function () {
--    let defaultVal = service[attrName];
--    is(defaultVal, expectedVal, attrName);
--
--    deferred.resolve(service);
--  }, 0);
-+  let defaultVal = service[attrName];
-+  is(defaultVal, expectedVal, attrName);
-+  return Promise.resolve(service);
- }
- 
- function getNumRadioInterfaces() {
--  let deferred = Promise.defer();
-+  let numRil = Services.prefs.getIntPref(PREF_RIL_NUM_RADIO_INTERFACES);
-+  log("numRil = " + numRil);
- 
--  window.setTimeout(function () {
--    let numRil = Services.prefs.getIntPref(PREF_RIL_NUM_RADIO_INTERFACES);
--    log("numRil = " + numRil);
--
--    deferred.resolve(numRil);
--  }, 0);
--
--  return deferred.promise;
-+  return Promise.resolve(numRil);
- }
- 
- function getService(contractId, ifaceName) {
--  let deferred = Promise.defer();
--
--  window.setTimeout(function () {
--    log("Getting service for " + ifaceName);
--    let service = Cc[contractId].getService(Ci[ifaceName]);
--    ok(service, "service.constructor is " + service.constructor);
--
--    deferred.resolve(service);
--  }, 0);
--
--  return deferred.promise;
-+  log("Getting service for " + ifaceName);
-+  let service = Cc[contractId].getService(Ci[ifaceName]);
-+  ok(service, "service.constructor is " + service.constructor);
-+  return Promise.resolve(service);
- }
- 
- function checkInitialEquality(attrName, prefKey, service) {
--  let deferred = Promise.defer();
--
-   log("  Checking initial value for '" + prefKey + "'");
-   let origPrefVal = Services.prefs.getIntPref(prefKey);
-   ok(isFinite(origPrefVal), "default '" + prefKey + "' value");
- 
--  window.setTimeout(function () {
--    let defaultVal = service[attrName];
--    is(defaultVal, origPrefVal, attrName);
--
--    deferred.resolve(service);
--  }, 0);
--
--  return deferred.promise;
-+  let defaultVal = service[attrName];
-+  is(defaultVal, origPrefVal, attrName);
-+  return Promise.resolve(service);
- }
- 
- function checkSetToNegtiveValue(attrName, prefKey, service) {
--  let deferred = Promise.defer();
--
-   // Set to -1 and verify defaultVal == 0.
--  setPrefAndVerify(prefKey, -1, service, attrName, 0, deferred);
--
--  return deferred.promise;
-+  return setPrefAndVerify(prefKey, -1, service, attrName, 0);
- }
- 
- function checkSetToOverflowedValue(attrName, prefKey, numRil, service) {
--  let deferred = Promise.defer();
--
-   // Set to larger-equal than numRil and verify defaultVal == 0.
--  setPrefAndVerify(prefKey, numRil, service, attrName, 0, deferred);
--
--  return deferred.promise;
-+  return setPrefAndVerify(prefKey, numRil, service, attrName, 0);
- }
- 
- function checkValueChange(attrName, prefKey, numRil, service) {
--  let deferred = Promise.defer();
--
-   if (numRil > 1) {
-     // Set to (numRil - 1) and verify defaultVal equals.
--    setPrefAndVerify(prefKey, numRil - 1, service, attrName, numRil - 1, deferred);
-+    return setPrefAndVerify(prefKey, numRil - 1, service, attrName, numRil - 1);
-   } else {
--    window.setTimeout(function () {
--      deferred.resolve(service);
--    }, 0);
-+    return Promise.resolve(service);
-   }
--
--  return deferred.promise;
- }
- 
- function verify(contractId, ifaceName, attrName, prefKey, numRil) {
--  let deferred = Promise.defer();
--
--  getService(contractId, ifaceName)
-+  return getService(contractId, ifaceName)
-     .then(checkInitialEquality.bind(null, attrName, prefKey))
-     .then(checkSetToNegtiveValue.bind(null, attrName, prefKey))
-     .then(checkSetToOverflowedValue.bind(null, attrName, prefKey, numRil))
-     .then(checkValueChange.bind(null, attrName, prefKey, numRil))
-     .then(function () {
-       // Reset.
-       Services.prefs.clearUserPref(prefKey);
- 
--      deferred.resolve(numRil);
-+      return numRil;
-     });
--
--  return deferred.promise;
- }
- 
- getNumRadioInterfaces()
-   .then(verify.bind(null, MMS_SERVICE_CONTRACTID, "nsIMmsService",
-                     "mmsDefaultServiceId", PREF_MMS_DEFAULT_SERVICE_ID))
-   .then(verify.bind(null, SMS_SERVICE_CONTRACTID, "nsISmsService",
-                     "smsDefaultServiceId", PREF_SMS_DEFAULT_SERVICE_ID))
-   .then(finish);
-diff --git a/dom/push/src/PushService.jsm b/dom/push/src/PushService.jsm
---- a/dom/push/src/PushService.jsm
-+++ b/dom/push/src/PushService.jsm
-@@ -17,17 +17,16 @@ const Ci = Components.interfaces;
- const Cu = Components.utils;
- const Cr = Components.results;
- 
- Cu.import("resource://gre/modules/XPCOMUtils.jsm");
- Cu.import("resource://gre/modules/Services.jsm");
- Cu.import("resource://gre/modules/IndexedDBHelper.jsm");
- Cu.import("resource://gre/modules/Timer.jsm");
- Cu.import("resource://gre/modules/Preferences.jsm");
--Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
- 
- XPCOMUtils.defineLazyModuleGetter(this, "AlarmService",
-                                   "resource://gre/modules/AlarmService.jsm");
- 
- this.EXPORTED_SYMBOLS = ["PushService"];
- 
- const prefs = new Preferences("services.push.");
- // Set debug first so that all debugging actually works.
-@@ -896,33 +895,32 @@ this.PushService = {
-    */
-   _sendRequest: function(action, data) {
-     debug("sendRequest() " + action);
-     if (typeof data.channelID !== "string") {
-       debug("Received non-string channelID");
-       return Promise.reject("Received non-string channelID");
-     }
- 
--    let deferred = Promise.defer();
--
-     if (Object.keys(this._pendingRequests).length == 0) {
-       // start the timer since we now have at least one request
-       if (!this._requestTimeoutTimer)
-         this._requestTimeoutTimer = Cc["@mozilla.org/timer;1"]
-                                       .createInstance(Ci.nsITimer);
-       this._requestTimeoutTimer.init(this,
-                                      this._requestTimeout,
-                                      Ci.nsITimer.TYPE_REPEATING_SLACK);
-     }
- 
--    this._pendingRequests[data.channelID] = { deferred: deferred,
--                                              ctime: Date.now() };
--
--    this._send(action, data);
--    return deferred.promise;
-+    return new Promise(function(resolve, reject) {
-+      this._pendingRequests[data.channelID] = { deferred: { resolve: resolve,
-+                                                            reject: reject },
-+                                                ctime: Date.now() };
-+      this._send(action, data);
-+    }.bind(this));
-   },
- 
-   _send: function(action, data) {
-     debug("send()");
-     this._requestQueue.push([action, data]);
-     debug("Queued " + action);
-     this._processNextRequestInQueue();
-   },
-@@ -999,20 +997,23 @@ this.PushService = {
-                             compareRecordVersionAndNotify.bind(this),
-                             recoverNoSuchChannelID.bind(this));
-   },
- 
-   // Fires a push-register system message to all applications that have
-   // registrations.
-   _notifyAllAppsRegister: function() {
-     debug("notifyAllAppsRegister()");
--    let deferred = Promise.defer();
-+
-+    let promise = new Promise(function(resolve, reject) {
-+      this._db.getAllChannelIDs(resolve, reject);
-+    });
- 
-     // records are objects describing the registrations as stored in IndexedDB.
--    function wakeupRegisteredApps(records) {
-+    return promise.then(function(records) {
-       // Pages to be notified.
-       // wakeupTable[manifestURL] -> [ pageURL ]
-       let wakeupTable = {};
-       for (let i = 0; i < records.length; i++) {
-         let record = records[i];
-         if (!(record.manifestURL in wakeupTable))
-           wakeupTable[record.manifestURL] = [];
- 
-@@ -1024,23 +1025,17 @@ this.PushService = {
- 
-       for (let manifestURL in wakeupTable) {
-         wakeupTable[manifestURL].forEach(function(pageURL) {
-           messenger.sendMessage('push-register', {},
-                                 Services.io.newURI(pageURL, null, null),
-                                 Services.io.newURI(manifestURL, null, null));
-         });
-       }
--
--      deferred.resolve();
--    }
--
--    this._db.getAllChannelIDs(wakeupRegisteredApps, deferred.reject);
--
--    return deferred.promise;
-+    });
-   },
- 
-   _notifyApp: function(aPushRecord) {
-     if (!aPushRecord || !aPushRecord.pageURL || !aPushRecord.manifestURL) {
-       debug("notifyApp() something is undefined.  Dropping notification");
-       return;
-     }
- 
-@@ -1054,25 +1049,25 @@ this.PushService = {
-     };
-     let messenger = Cc["@mozilla.org/system-message-internal;1"]
-                       .getService(Ci.nsISystemMessagesInternal);
-     messenger.sendMessage('push', message, pageURI, manifestURI);
-   },
- 
-   _updatePushRecord: function(aPushRecord) {
-     debug("updatePushRecord()");
--    let deferred = Promise.defer();
--    this._db.put(aPushRecord, deferred.resolve, deferred.reject);
--    return deferred.promise;
-+    return new Promise(function(resolve, reject) {
-+      this._db.put(aPushRecord, resolve, reject);
-+    }.bind(this));
-   },
- 
-   _dropRegistrations: function() {
--    let deferred = Promise.defer();
--    this._db.drop(deferred.resolve, deferred.reject);
--    return deferred.promise;
-+    return new Promise(function(resolve, reject) {
-+      this._db.drop(resolve, reject);
-+    }.bind(this));
-   },
- 
-   receiveMessage: function(aMessage) {
-     debug("receiveMessage(): " + aMessage.name);
- 
-     if (kCHILD_PROCESS_MESSAGES.indexOf(aMessage.name) == -1) {
-       debug("Invalid message from child " + aMessage.name);
-       return;
-@@ -1110,17 +1105,16 @@ this.PushService = {
-   },
- 
-   /**
-    * Exceptions thrown in _onRegisterSuccess are caught by the promise obtained
-    * from _sendRequest, causing the promise to be rejected instead.
-    */
-   _onRegisterSuccess: function(aPageRecord, generatedChannelID, data) {
-     debug("_onRegisterSuccess()");
--    let deferred = Promise.defer();
-     let message = { requestID: aPageRecord.requestID };
- 
-     if (typeof data.channelID !== "string") {
-       debug("Invalid channelID " + message);
-       message["error"] = "Invalid channelID received";
-       throw message;
-     }
-     else if (data.channelID != generatedChannelID) {
-@@ -1142,31 +1136,31 @@ this.PushService = {
-     let record = {
-       channelID: data.channelID,
-       pushEndpoint: data.pushEndpoint,
-       pageURL: aPageRecord.pageURL,
-       manifestURL: aPageRecord.manifestURL,
-       version: null
-     };
- 
--    this._updatePushRecord(record)
--      .then(
--        function() {
--          message["pushEndpoint"] = data.pushEndpoint;
--          deferred.resolve(message);
--        },
--        function(error) {
--          // Unable to save.
--          this._send("unregister", {channelID: record.channelID});
--          message["error"] = error;
--          deferred.reject(message);
--        }
--      );
-+    let p = this._updatePushRecord(record)
-+              .then(
-+                function() {
-+                  message["pushEndpoint"] = data.pushEndpoint;
-+                  return message;
-+                },
-+                function(error) {
-+                  // Unable to save.
-+                  this._send("unregister", {channelID: record.channelID});
-+                  message["error"] = error;
-+                  throw message;
-+                }
-+              );
- 
--    return deferred.promise;
-+    return p;
-   },
- 
-   /**
-    * Exceptions thrown in _onRegisterError are caught by the promise obtained
-    * from _sendRequest, causing the promise to be rejected instead.
-    */
-   _onRegisterError: function(aPageRecord, aMessageManager, reply) {
-     debug("_onRegisterError()");
-diff --git a/dom/system/gonk/tests/marionette/test_dsds_numRadioInterfaces.js b/dom/system/gonk/tests/marionette/test_dsds_numRadioInterfaces.js
---- a/dom/system/gonk/tests/marionette/test_dsds_numRadioInterfaces.js
-+++ b/dom/system/gonk/tests/marionette/test_dsds_numRadioInterfaces.js
-@@ -1,15 +1,14 @@
- /* Any copyright is dedicated to the Public Domain.
-  * http://creativecommons.org/publicdomain/zero/1.0/ */
- 
- MARIONETTE_TIMEOUT = 60000;
- MARIONETTE_CONTEXT = "chrome";
- 
--Cu.import("resource://gre/modules/Promise.jsm");
- Cu.import("resource://gre/modules/systemlibs.js");
- 
- const NS_RIL_CONTRACTID = "@mozilla.org/ril;1";
- 
- const PROP_RO_MOZ_RIL_NUMCLIENTS = "ro.moz.ril.numclients";
- 
- const PREF_RIL_NUM_RADIO_INTERFACES = "ril.numRadioInterfaces";
- 
-diff --git a/dom/telephony/gonk/TelephonyProvider.js b/dom/telephony/gonk/TelephonyProvider.js
---- a/dom/telephony/gonk/TelephonyProvider.js
-+++ b/dom/telephony/gonk/TelephonyProvider.js
-@@ -4,17 +4,16 @@
-  * You can obtain one at http://mozilla.org/MPL/2.0/. */
- 
- "use strict";
- 
- const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
- 
- Cu.import("resource://gre/modules/XPCOMUtils.jsm");
- Cu.import("resource://gre/modules/Services.jsm");
--Cu.import("resource://gre/modules/Promise.jsm");
- 
- var RIL = {};
- Cu.import("resource://gre/modules/ril_consts.js", RIL);
- 
- const GONK_TELEPHONYPROVIDER_CONTRACTID =
-   "@mozilla.org/telephony/gonktelephonyprovider;1";
- const GONK_TELEPHONYPROVIDER_CID =
-   Components.ID("{67d26434-d063-4d28-9f48-5b3189788155}");
-@@ -343,36 +342,38 @@ TelephonyProvider.prototype = {
- 
-     this._listeners.splice(index, 1);
-   },
- 
-   _enumerateCallsForClient: function _enumerateCallsForClient(aClientId,
-                                                               aListener) {
-     if (DEBUG) debug("Enumeration of calls for client " + aClientId);
- 
--    let deferred = Promise.defer();
-+    let promise = new Promise(function(resolve) {
-+      this._getClient(aClientId).sendWorkerMessage(
-+        "enumerateCalls", null,
-+        function(response) {
-+          resolve(response);
-+          return false; //XXXnsm This API uses a callback's return value!
-+        }
-+      );
-+    }.bind(this));
- 
--    this._getClient(aClientId).sendWorkerMessage("enumerateCalls", null,
--                                                 (function(response) {
-+    return promise.then(function(response) {
-       for (let call of response.calls) {
-         call.clienId = aClientId;
-         call.state = this._convertRILCallState(call.state);
-         call.isActive = this._matchActiveCall(call);
- 
-         aListener.enumerateCallState(call.clientId, call.callIndex,
-                                      call.state, call.number,
-                                      call.isActive, call.isOutgoing,
-                                      call.isEmergency, call.isConference);
-       }
--      deferred.resolve();
--
--      return false;
--    }).bind(this));
--
--    return deferred.promise;
-+    }.bind(this));
-   },
- 
-   enumerateCalls: function(aListener) {
-     if (DEBUG) debug("Requesting enumeration of calls for callback");
- 
-     let promise = Promise.resolve();
-     for (let i = 0; i < this._numClients; ++i) {
-       promise = promise.then(this._enumerateCallsForClient.bind(this, i, aListener));
-diff --git a/dom/telephony/test/marionette/head.js b/dom/telephony/test/marionette/head.js
---- a/dom/telephony/test/marionette/head.js
-+++ b/dom/telephony/test/marionette/head.js
-@@ -1,12 +1,11 @@
- /* Any copyright is dedicated to the Public Domain.
-  * http://creativecommons.org/publicdomain/zero/1.0/ */
- 
--let Promise = SpecialPowers.Cu.import("resource://gre/modules/Promise.jsm").Promise;
- let telephony;
- 
- /**
-  * Emulator helper.
-  */
- let emulator = (function() {
-   let pendingCmdCount = 0;
-   let originalRunEmulatorCmd = runEmulatorCmd;
-@@ -25,25 +24,23 @@ let emulator = (function() {
-       }
-     });
-   }
- 
-   /**
-    * @return Promise
-    */
-   function waitFinish() {
--    let deferred = Promise.defer();
--
--    waitFor(function() {
--      deferred.resolve();
--    }, function() {
--      return pendingCmdCount === 0;
-+    return new Promise(function(resolve) {
-+      waitFor(function() {
-+        resolve();
-+      }, function() {
-+        return pendingCmdCount === 0;
-+      });
-     });
--
--    return deferred.promise;
-   }
- 
-   return {
-     run: run,
-     waitFinish: waitFinish
-   };
- }());
- 
-@@ -58,33 +55,36 @@ let emulator = (function() {
-     ok(telephony.calls, 'telephony.calls');
-     is(telephony.calls.length, 0, 'telephony.calls.length');
-   }
- 
-   /**
-    * @return Promise
-    */
-   function clearCalls() {
--    let deferred = Promise.defer();
-+    log("Clear existing calls.");
- 
--    log("Clear existing calls.");
--    emulator.run("gsm clear", function(result) {
-+    let gsmClear = new Promise(function(resolve) {
-+      emulator.run("gsm clear", resolve);
-+    });
-+
-+    return gsmClear.then(function(result) {
-       if (result[0] == "OK") {
--        waitFor(function() {
--          deferred.resolve();
--        }, function() {
--          return telephony.calls.length === 0;
-+        return new Promise(function(resolve) {
-+          waitFor(function() {
-+            resolve();
-+          }, function() {
-+            return telephony.calls.length === 0;
-+          });
-         });
-       } else {
-         log("Failed to clear existing calls.");
--        deferred.reject();
-+        return Promise.reject();
-       }
-     });
--
--    return deferred.promise;
-   }
- 
-   this.checkInitialState = checkInitialState;
-   this.clearCalls = clearCalls;
- }());
- 
- function _startTest(permissions, test) {
-   function permissionSetUp() {
-diff --git a/dom/telephony/test/marionette/test_dsds_default_service_id.js b/dom/telephony/test/marionette/test_dsds_default_service_id.js
---- a/dom/telephony/test/marionette/test_dsds_default_service_id.js
-+++ b/dom/telephony/test/marionette/test_dsds_default_service_id.js
-@@ -1,127 +1,87 @@
- /* Any copyright is dedicated to the Public Domain.
-  * http://creativecommons.org/publicdomain/zero/1.0/ */
- 
- MARIONETTE_TIMEOUT = 60000;
- MARIONETTE_CONTEXT = "chrome";
- 
--Cu.import("resource://gre/modules/Promise.jsm");
--
- const TELEPHONY_PROVIDER_CONTRACTID =
-   "@mozilla.org/telephony/telephonyprovider;1";
- 
- const PREF_RIL_NUM_RADIO_INTERFACES = "ril.numRadioInterfaces";
- const PREF_DEFAULT_SERVICE_ID = "dom.telephony.defaultServiceId";
- 
--function setPrefAndVerify(prefKey, setVal, service, attrName, expectedVal, deferred) {
-+function setPrefAndVerify(prefKey, setVal, service, attrName, expectedVal) {
-   log("  Set '" + prefKey + "' to " + setVal);
-   Services.prefs.setIntPref(prefKey, setVal);
-   let prefVal = Services.prefs.getIntPref(prefKey);
-   is(prefVal, setVal, "'" + prefKey + "' set to " + setVal);
- 
--  window.setTimeout(function () {
-+  return Promise.resolve().then(function() {
-     let defaultVal = service[attrName];
-     is(defaultVal, expectedVal, attrName);
- 
--    deferred.resolve(service);
--  }, 0);
-+    return service;
-+  });
- }
- 
- function getNumRadioInterfaces() {
--  let deferred = Promise.defer();
--
--  window.setTimeout(function () {
--    let numRil = Services.prefs.getIntPref(PREF_RIL_NUM_RADIO_INTERFACES);
--    log("numRil = " + numRil);
--
--    deferred.resolve(numRil);
--  }, 0);
--
--  return deferred.promise;
-+  let numRil = Services.prefs.getIntPref(PREF_RIL_NUM_RADIO_INTERFACES);
-+  log("numRil = " + numRil);
-+  return Promise.resolve(numRil);
- }
- 
- function getService(contractId, ifaceName) {
--  let deferred = Promise.defer();
--
--  window.setTimeout(function () {
--    log("Getting service for " + ifaceName);
--    let service = Cc[contractId].getService(Ci[ifaceName]);
--    ok(service, "service.constructor is " + service.constructor);
--
--    deferred.resolve(service);
--  }, 0);
--
--  return deferred.promise;
-+  log("Getting service for " + ifaceName);
-+  let service = Cc[contractId].getService(Ci[ifaceName]);
-+  ok(service, "service.constructor is " + service.constructor);
-+  return Promise.resolve(service);
- }
- 
- function checkInitialEquality(attrName, prefKey, service) {
--  let deferred = Promise.defer();
--
-   log("  Checking initial value for '" + prefKey + "'");
-   let origPrefVal = Services.prefs.getIntPref(prefKey);
-   ok(isFinite(origPrefVal), "default '" + prefKey + "' value");
- 
--  window.setTimeout(function () {
--    let defaultVal = service[attrName];
--    is(defaultVal, origPrefVal, attrName);
-+  let defaultVal = service[attrName];
-+  is(defaultVal, origPrefVal, attrName);
- 
--    deferred.resolve(service);
--  }, 0);
--
--  return deferred.promise;
-+  return Promise.resolve(service);
- }
- 
- function checkSetToNegtiveValue(attrName, prefKey, service) {
--  let deferred = Promise.defer();
--
-   // Set to -1 and verify defaultVal == 0.
--  setPrefAndVerify(prefKey, -1, service, attrName, 0, deferred);
--
--  return deferred.promise;
-+  return setPrefAndVerify(prefKey, -1, service, attrName, 0);
- }
- 
- function checkSetToOverflowedValue(attrName, prefKey, numRil, service) {
--  let deferred = Promise.defer();
--
-   // Set to larger-equal than numRil and verify defaultVal == 0.
--  setPrefAndVerify(prefKey, numRil, service, attrName, 0, deferred);
--
--  return deferred.promise;
-+  return setPrefAndVerify(prefKey, numRil, service, attrName, 0);
- }
- 
- function checkValueChange(attrName, prefKey, numRil, service) {
--  let deferred = Promise.defer();
--
-   if (numRil > 1) {
-     // Set to (numRil - 1) and verify defaultVal equals.
--    setPrefAndVerify(prefKey, numRil - 1, service, attrName, numRil - 1, deferred);
-+    return setPrefAndVerify(prefKey, numRil - 1, service, attrName, numRil - 1);
-   } else {
--    window.setTimeout(function () {
--      deferred.resolve(service);
--    }, 0);
-+    return Promise.resolve(service);
-   }
--
--  return deferred.promise;
- }
- 
- function verify(contractId, ifaceName, attrName, prefKey, numRil) {
--  let deferred = Promise.defer();
--
--  getService(contractId, ifaceName)
-+  return getService(contractId, ifaceName)
-     .then(checkInitialEquality.bind(null, attrName, prefKey))
-     .then(checkSetToNegtiveValue.bind(null, attrName, prefKey))
-     .then(checkSetToOverflowedValue.bind(null, attrName, prefKey, numRil))
-     .then(checkValueChange.bind(null, attrName, prefKey, numRil))
-     .then(function () {
-       // Reset.
-       Services.prefs.clearUserPref(prefKey);
- 
--      deferred.resolve(numRil);
-+      return numRil;
-     });
--
--  return deferred.promise;
- }
- 
- getNumRadioInterfaces()
-   .then(verify.bind(null, TELEPHONY_PROVIDER_CONTRACTID, "nsITelephonyProvider",
-                     "defaultServiceId", PREF_DEFAULT_SERVICE_ID))
-   .then(finish);
-diff --git a/dom/telephony/test/marionette/test_outgoing_emergency_in_airplane_mode.js b/dom/telephony/test/marionette/test_outgoing_emergency_in_airplane_mode.js
---- a/dom/telephony/test/marionette/test_outgoing_emergency_in_airplane_mode.js
-+++ b/dom/telephony/test/marionette/test_outgoing_emergency_in_airplane_mode.js
-@@ -1,42 +1,38 @@
- /* Any copyright is dedicated to the Public Domain.
-  * http://creativecommons.org/publicdomain/zero/1.0/ */
- 
- MARIONETTE_TIMEOUT = 60000;
- MARIONETTE_HEAD_JS = 'head.js';
- 
--let Promise = SpecialPowers.Cu.import("resource://gre/modules/Promise.jsm").Promise;
--
- const KEY = "ril.radio.disabled";
- 
- let settings;
- let number = "112";
- let outgoing;
- 
- function setAirplaneMode() {
-   log("Turning on airplane mode");
- 
--  let deferred = Promise.defer();
--
-   let setLock = settings.createLock();
-   let obj = {};
-   obj[KEY] = false;
- 
-   let setReq = setLock.set(obj);
--  setReq.addEventListener("success", function onSetSuccess() {
--    ok(true, "set '" + KEY + "' to " + obj[KEY]);
--    deferred.resolve();
-+  return new Promise(function(resolve, reject) {
-+    setReq.addEventListener("success", function onSetSuccess() {
-+      ok(true, "set '" + KEY + "' to " + obj[KEY]);
-+      resolve();
-+    });
-+    setReq.addEventListener("error", function onSetError() {
-+      ok(false, "cannot set '" + KEY + "'");
-+      reject();
-+    });
-   });
--  setReq.addEventListener("error", function onSetError() {
--    ok(false, "cannot set '" + KEY + "'");
--    deferred.reject();
--  });
--
--  return deferred.promise;
- }
- 
- function dial() {
-   log("Make an outgoing call.");
- 
-   outgoing = telephony.dial(number);
-   ok(outgoing);
-   is(outgoing.number, number);
-diff --git a/dom/voicemail/test/marionette/test_dsds_default_service_id.js b/dom/voicemail/test/marionette/test_dsds_default_service_id.js
---- a/dom/voicemail/test/marionette/test_dsds_default_service_id.js
-+++ b/dom/voicemail/test/marionette/test_dsds_default_service_id.js
-@@ -1,107 +1,83 @@
- /* Any copyright is dedicated to the Public Domain.
-  * http://creativecommons.org/publicdomain/zero/1.0/ */
- 
- MARIONETTE_TIMEOUT = 60000;
- MARIONETTE_CONTEXT = "chrome";
- 
--Cu.import("resource://gre/modules/Promise.jsm");
--
- const VOICEMAIL_PROVIDER_CONTRACTID = "@mozilla.org/ril/content-helper;1";
- 
- const PREF_RIL_NUM_RADIO_INTERFACES = "ril.numRadioInterfaces";
- const PREF_DEFAULT_SERVICE_ID = "dom.voicemail.defaultServiceId";
- 
--function setPrefAndVerify(prefKey, setVal, service, attrName, expectedVal, deferred) {
-+function setPrefAndVerify(prefKey, setVal, service, attrName, expectedVal) {
-   log("  Set '" + prefKey + "' to " + setVal);
-   Services.prefs.setIntPref(prefKey, setVal);
-   let prefVal = Services.prefs.getIntPref(prefKey);
-   is(prefVal, setVal, "'" + prefKey + "' set to " + setVal);
- 
--  window.setTimeout(function () {
-+  // Promise.resolve() ensures the function is called on the next invocation of
-+  // the event loop.
-+  return Promise.resolve().then(function() {
-     let defaultVal = service[attrName];
-     is(defaultVal, expectedVal, attrName);
--
--    deferred.resolve(service);
--  }, 0);
-+    return service;
-+  });
- }
- 
- function getNumRadioInterfaces() {
--  let deferred = Promise.defer();
--
--  window.setTimeout(function () {
-+  return Promise.resolve().then(function() {
-     let numRil = Services.prefs.getIntPref(PREF_RIL_NUM_RADIO_INTERFACES);
-     log("numRil = " + numRil);
- 
--    deferred.resolve(numRil);
--  }, 0);
--
--  return deferred.promise;
-+    return numRil;
-+  });
- }
- 
- function getService(contractId, ifaceName) {
--  let deferred = Promise.defer();
--
--  window.setTimeout(function () {
-+  return Promise.resolve().then(function() {
-     log("Getting service for " + ifaceName);
-     let service = Cc[contractId].getService(Ci[ifaceName]);
-     ok(service, "service.constructor is " + service.constructor);
- 
--    deferred.resolve(service);
--  }, 0);
--
--  return deferred.promise;
-+    return service;
-+  });
- }
- 
- function checkInitialEquality(attrName, prefKey, service) {
--  let deferred = Promise.defer();
--
-   log("  Checking initial value for '" + prefKey + "'");
-   let origPrefVal = Services.prefs.getIntPref(prefKey);
-   ok(isFinite(origPrefVal), "default '" + prefKey + "' value");
- 
--  window.setTimeout(function () {
-+  let p = Promise.resolve();
-+
-+  return p.then(function() {
-     let defaultVal = service[attrName];
-     is(defaultVal, origPrefVal, attrName);
--
--    deferred.resolve(service);
--  }, 0);
--
--  return deferred.promise;
-+    return service;
-+  });
- }
- 
- function checkSetToNegtiveValue(attrName, prefKey, service) {
--  let deferred = Promise.defer();
--
-   // Set to -1 and verify defaultVal == 0.
--  setPrefAndVerify(prefKey, -1, service, attrName, 0, deferred);
--
--  return deferred.promise;
-+  return setPrefAndVerify(prefKey, -1, service, attrName, 0);
- }
- 
- function checkSetToOverflowedValue(attrName, prefKey, numRil, service) {
--  let deferred = Promise.defer();
--
-   // Set to larger-equal than numRil and verify defaultVal == 0.
--  setPrefAndVerify(prefKey, numRil, service, attrName, 0, deferred);
--
--  return deferred.promise;
-+  return setPrefAndVerify(prefKey, numRil, service, attrName, 0);
- }
- 
- function checkValueChange(attrName, prefKey, numRil, service) {
--  let deferred = Promise.defer();
--
-   if (numRil > 1) {
-     // Set to (numRil - 1) and verify defaultVal equals.
--    setPrefAndVerify(prefKey, numRil - 1, service, attrName, numRil - 1, deferred);
-+    return setPrefAndVerify(prefKey, numRil - 1, service, attrName, numRil - 1);
-   } else {
--    window.setTimeout(function () {
--      deferred.resolve(service);
--    }, 0);
-+    return Promise.resolve(service);
-   }
- 
-   return deferred.promise;
- }
- 
- function verify(contractId, ifaceName, attrName, prefKey, numRil) {
-   let deferred = Promise.defer();
- 
-diff --git a/dom/workers/test/xpcshell/test_workers.js b/dom/workers/test/xpcshell/test_workers.js
---- a/dom/workers/test/xpcshell/test_workers.js
-+++ b/dom/workers/test/xpcshell/test_workers.js
-@@ -1,42 +1,40 @@
- /* Any copyright is dedicated to the Public Domain.
-    http://creativecommons.org/publicdomain/zero/1.0/ */
- 
--Components.utils.import("resource://gre/modules/Promise.jsm");
--
- // Worker must be loaded from a chrome:// uri, not a file://
- // uri, so we first need to load it.
- let WORKER_SOURCE_URI = "chrome://workers/content/worker.js";
- do_load_manifest("data/chrome.manifest");
- 
- function run_test() {
-   run_next_test();
- }
- 
- function talk_with_worker(worker) {
--  let deferred = Promise.defer();
--  worker.onmessage = function(event) {
--    let success = true;
--    if (event.data == "OK") {
--      deferred.resolve();
--    } else {
--      success = false;
--      deferred.reject(event);
--    }
--    do_check_true(success);
--    worker.terminate();
--  };
--  worker.onerror = function(event) {
--    let error = new Error(event.message, event.filename, event.lineno);
--    worker.terminate();
--    deferred.reject(error);
--  };
--  worker.postMessage("START");
--  return deferred.promise;
-+  return new Promise(function(resolve, reject) {
-+    worker.onmessage = function(event) {
-+      let success = true;
-+      if (event.data == "OK") {
-+        resolve();
-+      } else {
-+        success = false;
-+        reject(event);
-+      }
-+      do_check_true(success);
-+      worker.terminate();
-+    };
-+    worker.onerror = function(event) {
-+      let error = new Error(event.message, event.filename, event.lineno);
-+      worker.terminate();
-+      reject(error);
-+    };
-+    worker.postMessage("START");
-+  });
- }
- 
- 
- add_task(function test_chrome_worker() {
-   return talk_with_worker(new ChromeWorker(WORKER_SOURCE_URI));
- });
- 
- add_task(function test_worker() {
--- a/series
+++ b/series
@@ -15,14 +15,13 @@ 903441-sw-nointercept
 foo
 898524-cache
 sw-install-tests2
 sw-more-install-tests
 943704-importscripts
 939636-toolkit
 939636-browser
 939636-testing
-939636-dom
 939636-promiseglobal
 939636-promisejsm
 promise-nsresult
 984048-swutil-fetcher
 984048-swm-update+