Smarter deep clone, fixes nw.js icon
This commit is contained in:
2 files changed
+26
-1
No files matched your search
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user