mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
allow deep copies of objects to optionally copy object properties in alphabetical order. This is useful to guarantee the order in which they would be serialized as json (which may depend on the order in which properties are added)
This commit is contained in:
parent
610f300600
commit
f1bea5c26d
@ -183,7 +183,7 @@ let Utils = {
|
||||
return true;
|
||||
},
|
||||
|
||||
deepCopy: function Weave_deepCopy(thing) {
|
||||
deepCopy: function Weave_deepCopy(thing, sort) {
|
||||
if (typeof(thing) != "object" || thing == null)
|
||||
return thing;
|
||||
let ret;
|
||||
@ -191,12 +191,14 @@ let Utils = {
|
||||
if ("Array" == thing.constructor.name) {
|
||||
ret = [];
|
||||
for (let i = 0; i < thing.length; i++)
|
||||
ret.push(Utils.deepCopy(thing[i]));
|
||||
ret.push(Utils.deepCopy(thing[i]), sort);
|
||||
|
||||
} else {
|
||||
ret = {};
|
||||
for (let key in thing)
|
||||
ret[key] = Utils.deepCopy(thing[key]);
|
||||
let props = [p for (p in thing)];
|
||||
if (sort)
|
||||
props = props.sort();
|
||||
props.forEach(function(k) ret[k] = Utils.deepCopy(thing[k], sort));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
Loading…
Reference in New Issue
Block a user