/* 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/. */ utils.common = { objToString: function (obj) { try { return '' + obj } catch (e) { return '[' + e + ']' } }, getAllProperties: function (obj) { let list = [] while (obj) { list = list.concat(Object.getOwnPropertyNames(obj)) obj = Object.getPrototypeOf(obj) } return list }, getKeysFromHash: function (obj) { let list = [] for (let p in obj) { list.push(p) } return list }, quote: function (obj) { return JSON.stringify(obj) }, uniqueList: function (list) { let tmp = {} let r = [] for (let i = 0; i < list.length; i++) { tmp[list[i]] = list[i] } for (let i in tmp) { r.push(tmp[i]) } return r }, mergeHash: function (obj1, obj2) { for (let p in obj2) { try { if (obj2[p].constructor === Object) { obj1[p] = utils.common.mergeHash(obj1[p], obj2[p]) } else { obj1[p] = obj2[p] } } catch (e) { obj1[p] = obj2[p] } } return obj1 } }