1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:17:44 +00:00

LibJS: Handle circular references in Array.prototype.toLocaleString()

Also use ArmedScopeGuard for removing seen objects to account for early
returns.

Fixes #3963.
This commit is contained in:
Linus Groh 2020-11-06 12:52:44 +00:00 committed by Andreas Kling
parent 15bc42479a
commit 82b42cefbd
3 changed files with 33 additions and 4 deletions

View file

@ -51,4 +51,12 @@ describe("normal behavior", () => {
expect([o, undefined, o, null, o].toLocaleString()).toBe("o,,o,,o");
expect(toStringCalled).toBe(3);
});
test("array with circular references", () => {
const a = ["foo", [], [1, 2, []], ["bar"]];
a[1] = a;
a[2][2] = a;
// [ "foo", <circular>, [ 1, 2, <circular> ], [ "bar" ] ]
expect(a.toLocaleString()).toBe("foo,,1,2,,bar");
});
});

View file

@ -55,4 +55,12 @@ describe("normal behavior", () => {
expect([o, undefined, o, null, o].toString()).toBe("o,,o,,o");
expect(toStringCalled).toBe(3);
});
test("array with circular references", () => {
const a = ["foo", [], [1, 2, []], ["bar"]];
a[1] = a;
a[2][2] = a;
// [ "foo", <circular>, [ 1, 2, <circular> ], [ "bar" ] ]
expect(a.toString()).toBe("foo,,1,2,,bar");
});
});