Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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/. */
5 "use strict";
7 this.EXPORTED_SYMBOLS = [
8 "TestingUtils",
9 ];
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 }
20 if (Array.isArray(thing)) {
21 let ret = [];
22 for (let element of thing) {
23 ret.push(this.deepCopy(element, noSort));
24 }
26 return ret;
27 }
29 let ret = {};
30 let props = [p for (p in thing)];
32 if (!noSort) {
33 props = props.sort();
34 }
36 for (let prop of props) {
37 ret[prop] = this.deepCopy(thing[prop], noSort);
38 }
40 return ret;
41 },
42 };