1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:08:11 +00:00

LibJS: Make Array.prototype.{join,toString}() generic

This commit is contained in:
Linus Groh 2020-05-22 15:04:52 +01:00 committed by Andreas Kling
parent e9ee06b19e
commit 040c75a3cc
3 changed files with 48 additions and 27 deletions

View file

@ -27,6 +27,22 @@ try {
assert(o.length === 0);
});
{
assert(Array.prototype.join.call({}) === "");
assert(Array.prototype.join.call({ length: "foo" }) === "");
assert(Array.prototype.join.call({ length: 3 }) === ",,");
assert(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar" }) === "foo,bar");
assert(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar", 2: "baz" }) === "foo,bar");
assert(Array.prototype.join.call({ length: 3, 1: "bar" }, "~") === "~bar~");
assert(Array.prototype.join.call({ length: 3, 0: "foo", 1: "bar", 2: "baz" }, "~") === "foo~bar~baz");
}
{
assert(Array.prototype.toString.call({}) === "[object Object]");
assert(Array.prototype.toString.call({ join: "foo" }) === "[object Object]");
assert(Array.prototype.toString.call({ join: () => "foo" }) === "foo");
}
const o = { length: 5, 0: "foo", 1: "bar", 3: "baz" };
{