Bug 996430 - Remove FxAccountsUtils.jsm. r=ttaubert.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 16 Apr 2014 20:48:00 -0700
changeset 179347 f1cbde906d5d59e558df56a292a059fbdf7e3396
parent 179346 f011f98832e26151590465d8211cdb759acaa05d
child 179348 70bb7587900c1a619ab3514e78999976f08d1c11
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersttaubert
bugs996430
milestone31.0a1
Bug 996430 - Remove FxAccountsUtils.jsm. r=ttaubert.
services/fxaccounts/FxAccounts.jsm
services/fxaccounts/FxAccountsUtils.jsm
services/fxaccounts/moz.build
--- a/services/fxaccounts/FxAccounts.jsm
+++ b/services/fxaccounts/FxAccounts.jsm
@@ -11,17 +11,16 @@ Cu.import("resource://gre/modules/Promis
 Cu.import("resource://gre/modules/osfile.jsm");
 Cu.import("resource://services-common/utils.js");
 Cu.import("resource://services-crypto/utils.js");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Timer.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import("resource://gre/modules/FxAccountsCommon.js");
-Cu.import("resource://gre/modules/FxAccountsUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "FxAccountsClient",
   "resource://gre/modules/FxAccountsClient.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "jwcrypto",
   "resource://gre/modules/identity/jwcrypto.jsm");
 
 // All properties exposed by the public FxAccounts API.
@@ -196,31 +195,72 @@ AccountState.prototype = {
                "reason and rejecting it due to a different user being signed in." +
                "Originally rejected with: " + reason);
       return Promise.reject(new Error("A different user signed in"));
     }
     return Promise.reject(error);
   },
 
 }
+
+/**
+ * Copies properties from a given object to another object.
+ *
+ * @param from (object)
+ *        The object we read property descriptors from.
+ * @param to (object)
+ *        The object that we set property descriptors on.
+ * @param options (object) (optional)
+ *        {keys: [...]}
+ *          Lets the caller pass the names of all properties they want to be
+ *          copied. Will copy all properties of the given source object by
+ *          default.
+ *        {bind: object}
+ *          Lets the caller specify the object that will be used to .bind()
+ *          all function properties we find to. Will bind to the given target
+ *          object by default.
+ */
+function copyObjectProperties(from, to, opts = {}) {
+  let keys = (opts && opts.keys) || Object.keys(from);
+  let thisArg = (opts && opts.bind) || to;
+
+  for (let prop of keys) {
+    let desc = Object.getOwnPropertyDescriptor(from, prop);
+
+    if (typeof(desc.value) == "function") {
+      desc.value = desc.value.bind(thisArg);
+    }
+
+    if (desc.get) {
+      desc.get = desc.get.bind(thisArg);
+    }
+
+    if (desc.set) {
+      desc.set = desc.set.bind(thisArg);
+    }
+
+    Object.defineProperty(to, prop, desc);
+  }
+}
+
 /**
  * The public API's constructor.
  */
 this.FxAccounts = function (mockInternal) {
   let internal = new FxAccountsInternal();
   let external = {};
 
   // Copy all public properties to the 'external' object.
   let prototype = FxAccountsInternal.prototype;
   let options = {keys: publicProperties, bind: internal};
-  FxAccountsUtils.copyObjectProperties(prototype, external, options);
+  copyObjectProperties(prototype, external, options);
 
   // Copy all of the mock's properties to the internal object.
   if (mockInternal && !mockInternal.onlySetInternal) {
-    FxAccountsUtils.copyObjectProperties(mockInternal, internal);
+    copyObjectProperties(mockInternal, internal);
   }
 
   if (mockInternal) {
     // Exposes the internal object for testing only.
     external.internal = internal;
   }
 
   return Object.freeze(external);
deleted file mode 100644
--- a/services/fxaccounts/FxAccountsUtils.jsm
+++ /dev/null
@@ -1,49 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
-* License, v. 2.0. If a copy of the MPL was not distributed with this file,
-* You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-"use strict";
-
-this.EXPORTED_SYMBOLS = ["FxAccountsUtils"];
-
-this.FxAccountsUtils = Object.freeze({
-  /**
-   * Copies properties from a given object to another object.
-   *
-   * @param from (object)
-   *        The object we read property descriptors from.
-   * @param to (object)
-   *        The object that we set property descriptors on.
-   * @param options (object) (optional)
-   *        {keys: [...]}
-   *          Lets the caller pass the names of all properties they want to be
-   *          copied. Will copy all properties of the given source object by
-   *          default.
-   *        {bind: object}
-   *          Lets the caller specify the object that will be used to .bind()
-   *          all function properties we find to. Will bind to the given target
-   *          object by default.
-   */
-  copyObjectProperties: function (from, to, opts = {}) {
-    let keys = (opts && opts.keys) || Object.keys(from);
-    let thisArg = (opts && opts.bind) || to;
-
-    for (let prop of keys) {
-      let desc = Object.getOwnPropertyDescriptor(from, prop);
-
-      if (typeof(desc.value) == "function") {
-        desc.value = desc.value.bind(thisArg);
-      }
-
-      if (desc.get) {
-        desc.get = desc.get.bind(thisArg);
-      }
-
-      if (desc.set) {
-        desc.set = desc.set.bind(thisArg);
-      }
-
-      Object.defineProperty(to, prop, desc);
-    }
-  }
-});
--- a/services/fxaccounts/moz.build
+++ b/services/fxaccounts/moz.build
@@ -7,15 +7,14 @@
 PARALLEL_DIRS += ['interfaces']
 
 TEST_DIRS += ['tests']
 
 EXTRA_JS_MODULES += [
   'Credentials.jsm',
   'FxAccounts.jsm',
   'FxAccountsClient.jsm',
-  'FxAccountsCommon.js',
-  'FxAccountsUtils.jsm'
+  'FxAccountsCommon.js'
 ]
 
 # For now, we will only be using the FxA manager in B2G.
 if CONFIG['MOZ_B2G']:
   EXTRA_JS_MODULES += ['FxAccountsManager.jsm']