1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:37:45 +00:00

LibJS: Implement ECMA-402 Array.prototype.toLocaleString

Turns out the only difference between our existing implementation and
the ECMA-402 implementation is we weren't passing the locales and
options list to each element.toLocaleString invocation.

This also adds spec comments to the definition.
This commit is contained in:
Timothy Flynn 2021-11-16 22:06:09 -05:00 committed by Linus Groh
parent c19c3205ff
commit 39ab1a8999
2 changed files with 41 additions and 8 deletions

View file

@ -59,4 +59,12 @@ describe("normal behavior", () => {
// [ "foo", <circular>, [ 1, 2, <circular> ], [ "bar" ] ]
expect(a.toLocaleString()).toBe("foo,,1,2,,bar");
});
test("with options", () => {
expect([12, 34].toLocaleString("en")).toBe("12");
expect([12, 34].toLocaleString("ar")).toBe("\u0661\u0662,\u0663\u0664");
expect([0.234].toLocaleString("en", { style: "percent" })).toBe("23%");
expect([0.234].toLocaleString("ar", { style: "percent" })).toBe("\u0662\u0663\u066a\u061c");
});
});