Commit ff956f4d authored by caitpotter88's avatar caitpotter88 Committed by Commit bot

[esnext] implement StringPad spec changes from March TC39 meeting

Return the empty string from StringPad if the filler argument is the empty
string, effectively returning the string unchanged in StringPadStart and
StringPadEnd.

```
"foo".padStart(100000, "") -> "foo"
```

BUG=v8:4957, v8:4954
LOG=N
R=littledan@chromium.org

Review-Url: https://codereview.chromium.org/1926773003
Cr-Commit-Position: refs/heads/master@{#35837}
parent 20360b08
......@@ -30,7 +30,8 @@ function StringPad(thisString, maxLength, fillString) {
} else {
fillString = TO_STRING(fillString);
if (fillString === "") {
fillString = " ";
// If filler is the empty String, return S.
return "";
}
}
......
......@@ -67,8 +67,19 @@
(function TestFillerToString() {
assertEquals(". ", ".".padEnd(10));
assertEquals(". ", ".".padEnd(10, undefined));
assertEquals(". ", ".".padEnd(10, { toString() { return ""; } }));
assertEquals(".nullnulln", ".".padEnd(10, null));
assertEquals(".XXXXXXXXX", ".".padEnd(10, { toString() { return "X"; } }));
assertEquals(
".111111111",
".".padEnd(10, { toString: undefined, valueOf() { return 1; } }));
})();
(function TestFillerEmptyString() {
assertEquals(".", ".".padEnd(10, ""));
assertEquals(".", ".".padEnd(10, { toString() { return ""; } }));
assertEquals(
".", ".".padEnd(10, { toString: undefined, valueOf() { return ""; } }));
})();
......
......@@ -67,8 +67,19 @@
(function TestFillerToString() {
assertEquals(" .", ".".padStart(10));
assertEquals(" .", ".".padStart(10, undefined));
assertEquals(" .", ".".padStart(10, { toString() { return ""; } }));
assertEquals("nullnulln.", ".".padStart(10, null));
assertEquals("XXXXXXXXX.", ".".padStart(10, { toString() { return "X"; } }));
assertEquals(
"111111111.",
".".padStart(10, { toString: undefined, valueOf() { return 1; } }));
})();
(function TestFillerEmptyString() {
assertEquals(".", ".".padStart(10, ""));
assertEquals(".", ".".padStart(10, { toString() { return ""; } }));
assertEquals(
".", ".".padStart(10, { toString: undefined, valueOf() { return ""; } }));
})();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment