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:
parent
15bc42479a
commit
82b42cefbd
3 changed files with 33 additions and 4 deletions
|
@ -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");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue