https://bugs.webkit.org/show_bug.cgi?id=157139
Reviewed by Keith Miller.
Previously, if the fill string was the empty string, it was treated as a
single U+0020 SPACE character. Now, if this occurs, the original string
is returned instead.
Change was discussed at TC39 in March [1], and is reflected in new
test262 tests for the feature.
[1] https://github.com/tc39/tc39-notes/blob/master/es7/2016-03/march-29.md#stringprototypepadstartpadend
* runtime/StringPrototype.cpp:
(JSC::padString):
* tests/es6/String.prototype_methods_String.prototype.padEnd.js:
(TestFillerToString):
(TestFillerEmptyString):
* tests/es6/String.prototype_methods_String.prototype.padStart.js:
(TestFillerToString):
(TestFillerEmptyString):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200194
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2016-04-28 Caitlin Potter <caitp@igalia.com>
+
+ [JSC] implement spec changes for String#padStart and String#padEnd
+ https://bugs.webkit.org/show_bug.cgi?id=157139
+
+ Reviewed by Keith Miller.
+
+ Previously, if the fill string was the empty string, it was treated as a
+ single U+0020 SPACE character. Now, if this occurs, the original string
+ is returned instead.
+
+ Change was discussed at TC39 in March [1], and is reflected in new
+ test262 tests for the feature.
+
+ [1] https://github.com/tc39/tc39-notes/blob/master/es7/2016-03/march-29.md#stringprototypepadstartpadend
+
+ * runtime/StringPrototype.cpp:
+ (JSC::padString):
+ * tests/es6/String.prototype_methods_String.prototype.padEnd.js:
+ (TestFillerToString):
+ (TestFillerEmptyString):
+ * tests/es6/String.prototype_methods_String.prototype.padStart.js:
+ (TestFillerToString):
+ (TestFillerEmptyString):
+
2016-04-28 Skachkov Oleksandr <gskachkov@gmail.com>
Crash for non-static super property call in derived class constructor
filler = fillString.toString(&exec);
if (!filler)
return JSValue::encode(jsUndefined());
+ if (!filler->length())
+ return JSValue::encode(thisString);
}
unsigned fillLength = static_cast<unsigned>(maxLength) - thisString->length();
return JSValue::encode(throwOutOfMemoryError(&exec));
}
- if (!filler || filler->length() <= 1) {
+ if (!filler || filler->length() == 1) {
UChar character = filler && filler->length() ? filler->view(&exec)[0] : ' ';
if (!(character & ~0xff))
filler = repeatCharacter(exec, static_cast<LChar>(character), fillLength);
(function TestFillerToString() {
shouldBe(". ", ".".padEnd(10));
shouldBe(". ", ".".padEnd(10, undefined));
- shouldBe(". ", ".".padEnd(10, { toString() { return ""; } }));
+ shouldBe(".XXXXXXXXX", ".".padEnd(10, { toString() { return "X"; } }));
+ shouldBe(".111111111", ".".padEnd(10, { toString: undefined, valueOf() { return 1; } }));
shouldBe(".nullnulln", ".".padEnd(10, null));
})();
+(function TestFillerEmptyString() {
+ shouldBe(".", ".".padEnd(10000, ""));
+ shouldBe(".", ".".padEnd(10000, { toString() { return ""; } }));
+ shouldBe(".", ".".padEnd(10000, { toString: undefined, valueOf() { return ""; } }));
+})();
+
(function TestSingleCharacterFiller() {
shouldBe(".!!!!!!!!!", ".".padEnd(10, "!"));
shouldBe(".!!!!!!!!!", ".".padEnd(10, { toString() { return "!"; } }));
(function TestFillerToString() {
shouldBe(" .", ".".padStart(10));
shouldBe(" .", ".".padStart(10, undefined));
- shouldBe(" .", ".".padStart(10, { toString() { return ""; } }));
+ shouldBe("XXXXXXXXX.", ".".padStart(10, { toString() { return "X"; } }));
+ shouldBe("111111111.", ".".padStart(10, { toString: undefined, valueOf() { return 1; } }));
shouldBe("nullnulln.", ".".padStart(10, null));
})();
+(function TestFillerEmptyString() {
+ shouldBe(".", ".".padStart(10000, ""));
+ shouldBe(".", ".".padStart(10000, { toString() { return ""; } }));
+ shouldBe(".", ".".padStart(10000, { toString: undefined, valueOf() { return ""; } }));
+})();
+
(function TestSingleCharacterFiller() {
shouldBe("!!!!!!!!!.", ".".padStart(10, "!"));
shouldBe("!!!!!!!!!.", ".".padStart(10, { toString() { return "!"; } }));