From 9f7a6e116ac40e725644b78bb265fc041cc1ef16 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 22 May 2020 14:01:35 +0100 Subject: [PATCH] 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() --- Libraries/LibJS/Runtime/ArrayPrototype.cpp | 2 +- Libraries/LibJS/Tests/Array.prototype.join.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Libraries/LibJS/Runtime/ArrayPrototype.cpp index 4be61e58ab..b9ff84a0ab 100644 --- a/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -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 {}; diff --git a/Libraries/LibJS/Tests/Array.prototype.join.js b/Libraries/LibJS/Tests/Array.prototype.join.js index 0221aacfd3..fc82deb20c 100644 --- a/Libraries/LibJS/Tests/Array.prototype.join.js +++ b/Libraries/LibJS/Tests/Array.prototype.join.js @@ -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() === "");