[sprout] Make mutate incrementally attempt to add property

Previously, we stored a global count variable that was updated every time we 
added a property to the `arg` object. This was added to prevent collisions, and 
make sure we do actually mutate the object. 

But the count value was shared by the forget compiled and uncompiled versions, 
so the same object mutated in either versions would result in having different 
properties leading to potential test failures. 

Instead, let's make count local and attempt to incrementally mutate the object 
with different keys.
This commit is contained in:
Sathya Gunasekaran
2023-10-04 12:36:04 +05:30
parent 3aaf8be25c
commit 0f97ea4c71
3 changed files with 16 additions and 6 deletions
@@ -9,7 +9,7 @@ function Component(a) {
let obj = {
method() {
mutate(x);
return x.a;
return x;
},
};
return obj.method();
@@ -32,7 +32,7 @@ function Component(a) {
const obj = {
method() {
mutate(x);
return x.a;
return x;
},
};
return obj.method();
@@ -5,7 +5,7 @@ function Component(a) {
let obj = {
method() {
mutate(x);
return x.a;
return x;
},
};
return obj.method();
+13 -3
View File
@@ -34,11 +34,21 @@ export const CONST_NUMBER2 = 2;
export const CONST_TRUE = true;
export const CONST_FALSE = false;
let count: number = 0;
export function mutate(arg: any): void {
// don't mutate primitive
if (typeof arg != null && typeof arg === "object") {
arg["wat" + count++] = "joe";
if (typeof arg === null || typeof arg !== "object") {
return;
}
let count: number = 0;
let key;
while (true) {
key = "wat" + count;
if (!Object.hasOwn(arg, key)) {
arg[key] = "joe";
return;
}
count++;
}
}