michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: this.EXPORTED_SYMBOLS = [ michael@0: "TestingUtils", michael@0: ]; michael@0: michael@0: this.TestingUtils = { michael@0: /** michael@0: * Perform a deep copy of an Array or Object. michael@0: */ michael@0: deepCopy: function deepCopy(thing, noSort) { michael@0: if (typeof(thing) != "object" || thing == null) { michael@0: return thing; michael@0: } michael@0: michael@0: if (Array.isArray(thing)) { michael@0: let ret = []; michael@0: for (let element of thing) { michael@0: ret.push(this.deepCopy(element, noSort)); michael@0: } michael@0: michael@0: return ret; michael@0: } michael@0: michael@0: let ret = {}; michael@0: let props = [p for (p in thing)]; michael@0: michael@0: if (!noSort) { michael@0: props = props.sort(); michael@0: } michael@0: michael@0: for (let prop of props) { michael@0: ret[prop] = this.deepCopy(thing[prop], noSort); michael@0: } michael@0: michael@0: return ret; michael@0: }, michael@0: };