Commit 31ad3b87 authored by Rob Campbell's avatar Rob Campbell
Browse files

merge fx-team to m-c

parents d4f40018 89af42f6
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -32,7 +32,14 @@ libs::

TEST_DIRS += tests

TESTING_JS_MODULES := aitcserver.js storageserver.js
testing_modules := \
  aitcserver.js \
  storageserver.js \
  utils.js \
  $(NULL)

TESTING_JS_MODULES := $(foreach file,$(testing_modules),modules-testing/$(file))

TESTING_JS_MODULE_DIR := services-common

# What follows is a helper to launch a standalone storage server instance.
+42 −0
Original line number Diff line number Diff line
/* 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";

const EXPORTED_SYMBOLS = [
  "TestingUtils",
];

let TestingUtils = {
  /**
   * Perform a deep copy of an Array or Object.
   */
  deepCopy: function deepCopy(thing, noSort) {
    if (typeof(thing) != "object" || thing == null) {
      return thing;
    }

    if (Array.isArray(thing)) {
      let ret = [];
      for (let element of thing) {
        ret.push(this.deepCopy(element, noSort));
      }

      return ret;
    }

    let ret = {};
    let props = [p for (p in thing)];

    if (!noSort) {
      props = props.sort();
    }

    for (let prop of props) {
      ret[prop] = this.deepCopy(thing[prop], noSort);
    }

    return ret;
  },
};
+5 −2
Original line number Diff line number Diff line
Cu.import("resource://services-sync/util.js");
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

Cu.import("resource://testing-common/services-common/utils.js");

function run_test() {
  let thing = {o: {foo: "foo", bar: ["bar"]}, a: ["foo", {bar: "bar"}]};
  let ret = deepCopy(thing);
  let ret = TestingUtils.deepCopy(thing);
  do_check_neq(ret, thing)
  do_check_neq(ret.o, thing.o);
  do_check_neq(ret.o.bar, thing.o.bar);
Loading