relative / synchrony

javascript-obfuscator cleaner & deobfuscator
https://deobfuscate.relative.im/
GNU General Public License v3.0
840 stars 108 forks source link

Update helpers.ts fix for #134 #136

Open pabx06 opened 7 months ago

pabx06 commented 7 months ago

fix for #134 JSON.parse(JSON.stringify(item)) have trouble on large object

relative commented 7 months ago

the spread operator won't work here since it only clones the top level keys

j4k0xb commented 7 months ago

maybe the code can be refactored to avoid cloning altogether. like here it shouldn't make a difference if it uses the original node or a copy: https://github.com/relative/synchrony/blob/721cf5dcd410f9c603484f21ceaae1f2a07deaff/src/transformers/simplify.ts#L225-L231 the only place where it might be necessary is related to control flow functions

pabx06 commented 7 months ago

Pretty sure this one is better

-native deep clone: structuredClone: https://developer.mozilla.org/en-US/docs/Web/API/structuredClone

j4k0xb commented 7 months ago

based on my tests structuredClone is a fair bit slower than json parse/stringify, but as long as it fixes the issue it shouldn't matter too much but there are some significantly faster alternatives that could also be used: https://github.com/lukeed/klona/blob/master/src/json.js (benchmark), can even improve the perf by another 25% by not checking for __proto__