services/common/modules-testing/utils.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:fcb775068e4e
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 "use strict";
6
7 this.EXPORTED_SYMBOLS = [
8 "TestingUtils",
9 ];
10
11 this.TestingUtils = {
12 /**
13 * Perform a deep copy of an Array or Object.
14 */
15 deepCopy: function deepCopy(thing, noSort) {
16 if (typeof(thing) != "object" || thing == null) {
17 return thing;
18 }
19
20 if (Array.isArray(thing)) {
21 let ret = [];
22 for (let element of thing) {
23 ret.push(this.deepCopy(element, noSort));
24 }
25
26 return ret;
27 }
28
29 let ret = {};
30 let props = [p for (p in thing)];
31
32 if (!noSort) {
33 props = props.sort();
34 }
35
36 for (let prop of props) {
37 ret[prop] = this.deepCopy(thing[prop], noSort);
38 }
39
40 return ret;
41 },
42 };

mercurial