-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
When using --transform-object-keys true in some cases const object is created outside of loop that used inside of each loop iteration (but this kind of loop optimization is not valid and obvious if you want create multiple new objects with same params inside of loop). This is a bug or feature?
Expected Behavior
Create a new object with same params inside of loop for each loop iteration
Current Behavior
One object is used inside of loop and as reasult all array params point to same object in memory
Steps to Reproduce
- Input file (./out/test.js):
!function() {
let o = [];
for (let e = 0; e < 10; e++)
o.push({o: 0 });
o[0].o = 1;
console.log(o[0] === o[1]); // this should be false
}();
- Obfuscate only with "--transform-object-keys true" and turn off default params to get easy readable results:
javascript-obfuscator ./out/test.js --output ./out/test_.js --transform-object-keys true --string-array false --compact false --simplify false --string-array-index-shift false --identifier-names-generator mangled --string-array-rotate false --string-array-shuffle false --string-array-wrappers-chained-calls false
- Got output file (./out/test_.js):
!(function () {
let b = [];
const c = {};
c['o'] = 0x0;
for (let d = 0x0; d < 0xa; d++)
b['push'](c);
b[0x0]['o'] = 0x1;
console['log'](b[0x0] === b[0x1]); // this is true not false due to same object
}());
Your Environment
- Obfuscator version used:
4.0.2_2023-02-13T06:57:01.273Z
- Node version used:
v18.17.0
Temporary solution
Rewrite object creation as follows Object.create({...}) in case of new object should be created per each iteration