mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-19 15:58:56 +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
Notes:
sideshowbarker
2024-07-19 01:32:38 +09:00
Author: https://github.com/linusg
Commit: 82b42cefbd
Pull-request: https://github.com/SerenityOS/serenity/pull/3965
Issue: https://github.com/SerenityOS/serenity/issues/3963
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