Smarter deep clone, fixes nw.js icon

This commit is contained in:
Thomas Weber committed 2021-06-24 14:09:16 -05:00
1 parent ca1d35cf81
commit fde210a2b0
2 files changed
+26 -1

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
const deepClone = (obj) => {
if (obj instanceof Blob) {
return obj;
}
if (Array.isArray(obj)) {
const result = [];
for (const value of obj) {
result.push(deepClone(value));
}
return result;
}
if (obj && typeof obj === 'object') {
// TODO: there's probably some prototype pollution in here
const result = {};
for (const key of Object.keys(obj)) {
result[key] = deepClone(obj[key]);
}
return result;
}
// Primitive type
return obj;
};
export default deepClone;
+2 -1
View File
@@ -5,6 +5,7 @@ import {readAsArrayBuffer, readAsURL} from './lib/readers';
import largeAssets from './large-assets';
import xhr from './lib/xhr';
import pngToAppleICNS from './lib/icns';
import deepClone from './lib/deep-clone';
const escapeXML = (v) => v.replace(/["'<>&]/g, (i) => {
switch (i) {
@@ -54,7 +55,7 @@ class Packager extends EventTarget {
child () {
const packager = new Packager();
packager.options = JSON.parse(JSON.stringify(this.options));
packager.options = deepClone(this.options);
packager.vm = this.vm;
packager.serialized = this.serialized;
return packager;