LibJS: Let Array.prototype.join() ignore additional arguments

I.e.

array.join("x", "y", "z") === array.join("x")

rather than

array.join("x", "y", "z") === array.join()
This commit is contained in:
Linus Groh 2020-05-22 14:01:35 +01:00 committed by Andreas Kling
parent 9fc4ad2a52
commit 9f7a6e116a
Notes: sideshowbarker 2024-07-19 06:15:26 +09:00
2 changed files with 2 additions and 1 deletions

View file

@ -239,7 +239,7 @@ Value ArrayPrototype::join(Interpreter& interpreter)
return {};
String separator = ",";
if (interpreter.argument_count() == 1) {
if (interpreter.argument_count()) {
separator = interpreter.argument(0).to_string(interpreter);
if (interpreter.exception())
return {};

View file

@ -5,6 +5,7 @@ try {
assert(["hello", "friends"].join() === "hello,friends");
assert(["hello", "friends"].join(" ") === "hello friends");
assert(["hello", "friends", "foo"].join("~", "#") === "hello~friends~foo");
assert([].join() === "");
assert([null].join() === "");
assert([undefined].join() === "");