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

LibJS: Handle empty values in Array.prototype.toString()

This commit is contained in:
Linus Groh 2020-04-08 18:56:12 +01:00 committed by Andreas Kling
parent 5c90cfa90f
commit 531335f57c
2 changed files with 8 additions and 1 deletions

View file

@ -100,7 +100,8 @@ Value ArrayPrototype::to_string(Interpreter& interpreter)
for (size_t i = 0; i < array->elements().size(); ++i) {
if (i != 0)
builder.append(',');
builder.append(array->elements()[i].to_string());
if (!array->elements()[i].is_empty())
builder.append(array->elements()[i].to_string());
}
return js_string(interpreter, builder.to_string());
}

View file

@ -6,6 +6,12 @@ try {
assert("rgb(" + [10, 11, 12] + ")" === "rgb(10,11,12)");
a = new Array(5);
assert(a.toString() === ",,,,");
a[2] = "foo";
a[4] = "bar";
assert(a.toString() === ",,foo,,bar");
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);