<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[198674] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/198674">198674</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-03-25 10:37:48 -0700 (Fri, 25 Mar 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>[JSC] implement String.prototype.padStart() and String.prototype.padEnd() proposal
https://bugs.webkit.org/show_bug.cgi?id=155795
Patch by Caitlin Potter <caitp@igalia.com> on 2016-03-25
Reviewed by Darin Adler.
Source/JavaScriptCore:
Implements ECMAScript proposal http://tc39.github.io/proposal-string-pad-start-end/
Currently at Stage 3.
* runtime/JSString.h:
* runtime/StringPrototype.cpp:
(JSC::StringPrototype::finishCreation):
(JSC::repeatCharacter):
(JSC::repeatStringPattern):
(JSC::padString):
(JSC::stringProtoFuncPadEnd):
(JSC::stringProtoFuncPadStart):
* tests/es6.yaml:
* tests/es6/String.prototype_methods_String.prototype.padEnd.js: Added.
* tests/es6/String.prototype_methods_String.prototype.padStart.js: Added.
LayoutTests:
* js/Object-getOwnPropertyNames-expected.txt:
* js/script-tests/Object-getOwnPropertyNames.js:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsjsObjectgetOwnPropertyNamesexpectedtxt">trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsscripttestsObjectgetOwnPropertyNamesjs">trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSStringh">trunk/Source/JavaScriptCore/runtime/JSString.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeStringPrototypecpp">trunk/Source/JavaScriptCore/runtime/StringPrototype.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoretestses6yaml">trunk/Source/JavaScriptCore/tests/es6.yaml</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoretestses6Stringprototype_methods_StringprototypepadEndjs">trunk/Source/JavaScriptCore/tests/es6/String.prototype_methods_String.prototype.padEnd.js</a></li>
<li><a href="#trunkSourceJavaScriptCoretestses6Stringprototype_methods_StringprototypepadStartjs">trunk/Source/JavaScriptCore/tests/es6/String.prototype_methods_String.prototype.padStart.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (198673 => 198674)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-03-25 17:24:33 UTC (rev 198673)
+++ trunk/LayoutTests/ChangeLog        2016-03-25 17:37:48 UTC (rev 198674)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2016-03-25 Caitlin Potter <caitp@igalia.com>
+
+ [JSC] implement String.prototype.padStart() and String.prototype.padEnd() proposal
+ https://bugs.webkit.org/show_bug.cgi?id=155795
+
+ Reviewed by Darin Adler.
+
+ * js/Object-getOwnPropertyNames-expected.txt:
+ * js/script-tests/Object-getOwnPropertyNames.js:
+
</ins><span class="cx"> 2016-03-25 Youenn Fablet <youenn.fablet@crf.canon.fr>
</span><span class="cx">
</span><span class="cx"> [Fetch API] Add basic loading of resources
</span></span></pre></div>
<a id="trunkLayoutTestsjsObjectgetOwnPropertyNamesexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt (198673 => 198674)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt        2016-03-25 17:24:33 UTC (rev 198673)
+++ trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt        2016-03-25 17:37:48 UTC (rev 198674)
</span><span class="lines">@@ -48,7 +48,7 @@
</span><span class="cx"> PASS getSortedOwnPropertyNames(Array) is ['from', 'isArray', 'length', 'name', 'of', 'prototype']
</span><span class="cx"> PASS getSortedOwnPropertyNames(Array.prototype) is ['concat', 'constructor', 'copyWithin', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'forEach', 'includes', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift', 'values']
</span><span class="cx"> PASS getSortedOwnPropertyNames(String) is ['fromCharCode', 'fromCodePoint', 'length', 'name', 'prototype', 'raw']
</span><del>-PASS getSortedOwnPropertyNames(String.prototype) is ['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'codePointAt', 'concat', 'constructor', 'endsWith', 'fixed', 'fontcolor', 'fontsize', 'includes', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'normalize', 'repeat', 'replace', 'search', 'slice', 'small', 'split', 'startsWith', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'valueOf']
</del><ins>+PASS getSortedOwnPropertyNames(String.prototype) is ['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'codePointAt', 'concat', 'constructor', 'endsWith', 'fixed', 'fontcolor', 'fontsize', 'includes', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'normalize', 'padEnd', 'padStart', 'repeat', 'replace', 'search', 'slice', 'small', 'split', 'startsWith', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'valueOf']
</ins><span class="cx"> PASS getSortedOwnPropertyNames(Boolean) is ['length', 'name', 'prototype']
</span><span class="cx"> PASS getSortedOwnPropertyNames(Boolean.prototype) is ['constructor', 'toString', 'valueOf']
</span><span class="cx"> PASS getSortedOwnPropertyNames(Number) is ['EPSILON', 'MAX_SAFE_INTEGER', 'MAX_VALUE', 'MIN_SAFE_INTEGER', 'MIN_VALUE', 'NEGATIVE_INFINITY', 'NaN', 'POSITIVE_INFINITY', 'isFinite', 'isInteger', 'isNaN', 'isSafeInteger', 'length', 'name', 'parseFloat', 'parseInt', 'prototype']
</span></span></pre></div>
<a id="trunkLayoutTestsjsscripttestsObjectgetOwnPropertyNamesjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js (198673 => 198674)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js        2016-03-25 17:24:33 UTC (rev 198673)
+++ trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js        2016-03-25 17:37:48 UTC (rev 198674)
</span><span class="lines">@@ -57,7 +57,7 @@
</span><span class="cx"> "Array": "['from', 'isArray', 'length', 'name', 'of', 'prototype']",
</span><span class="cx"> "Array.prototype": "['concat', 'constructor', 'copyWithin', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'forEach', 'includes', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift', 'values']",
</span><span class="cx"> "String": "['fromCharCode', 'fromCodePoint', 'length', 'name', 'prototype', 'raw']",
</span><del>- "String.prototype": "['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'codePointAt', 'concat', 'constructor', 'endsWith', 'fixed', 'fontcolor', 'fontsize', 'includes', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'normalize', 'repeat', 'replace', 'search', 'slice', 'small', 'split', 'startsWith', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'valueOf']",
</del><ins>+ "String.prototype": "['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'codePointAt', 'concat', 'constructor', 'endsWith', 'fixed', 'fontcolor', 'fontsize', 'includes', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'normalize', 'padEnd', 'padStart', 'repeat', 'replace', 'search', 'slice', 'small', 'split', 'startsWith', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'valueOf']",
</ins><span class="cx"> "Boolean": "['length', 'name', 'prototype']",
</span><span class="cx"> "Boolean.prototype": "['constructor', 'toString', 'valueOf']",
</span><span class="cx"> "Number": "['EPSILON', 'MAX_SAFE_INTEGER', 'MAX_VALUE', 'MIN_SAFE_INTEGER', 'MIN_VALUE', 'NEGATIVE_INFINITY', 'NaN', 'POSITIVE_INFINITY', 'isFinite', 'isInteger', 'isNaN', 'isSafeInteger', 'length', 'name', 'parseFloat', 'parseInt', 'prototype']",
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (198673 => 198674)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-03-25 17:24:33 UTC (rev 198673)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-03-25 17:37:48 UTC (rev 198674)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2016-03-25 Caitlin Potter <caitp@igalia.com>
+
+ [JSC] implement String.prototype.padStart() and String.prototype.padEnd() proposal
+ https://bugs.webkit.org/show_bug.cgi?id=155795
+
+ Reviewed by Darin Adler.
+
+ Implements ECMAScript proposal http://tc39.github.io/proposal-string-pad-start-end/
+ Currently at Stage 3.
+
+ * runtime/JSString.h:
+ * runtime/StringPrototype.cpp:
+ (JSC::StringPrototype::finishCreation):
+ (JSC::repeatCharacter):
+ (JSC::repeatStringPattern):
+ (JSC::padString):
+ (JSC::stringProtoFuncPadEnd):
+ (JSC::stringProtoFuncPadStart):
+ * tests/es6.yaml:
+ * tests/es6/String.prototype_methods_String.prototype.padEnd.js: Added.
+ * tests/es6/String.prototype_methods_String.prototype.padStart.js: Added.
+
</ins><span class="cx"> 2016-03-24 Alex Christensen <achristensen@webkit.org>
</span><span class="cx">
</span><span class="cx"> Fix Mac CMake build.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSStringh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSString.h (198673 => 198674)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSString.h        2016-03-25 17:24:33 UTC (rev 198673)
+++ trunk/Source/JavaScriptCore/runtime/JSString.h        2016-03-25 17:37:48 UTC (rev 198674)
</span><span class="lines">@@ -87,6 +87,8 @@
</span><span class="cx"> static const bool needsDestruction = true;
</span><span class="cx"> static void destroy(JSCell*);
</span><span class="cx">
</span><ins>+ static const unsigned MaxLength = std::numeric_limits<int32_t>::max();
+
</ins><span class="cx"> private:
</span><span class="cx"> JSString(VM& vm, PassRefPtr<StringImpl> value)
</span><span class="cx"> : JSCell(vm, vm.stringStructure.get())
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeStringPrototypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/StringPrototype.cpp (198673 => 198674)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/StringPrototype.cpp        2016-03-25 17:24:33 UTC (rev 198673)
+++ trunk/Source/JavaScriptCore/runtime/StringPrototype.cpp        2016-03-25 17:37:48 UTC (rev 198674)
</span><span class="lines">@@ -66,6 +66,8 @@
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL stringProtoFuncConcat(ExecState*);
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL stringProtoFuncIndexOf(ExecState*);
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL stringProtoFuncLastIndexOf(ExecState*);
</span><ins>+EncodedJSValue JSC_HOST_CALL stringProtoFuncPadEnd(ExecState*);
+EncodedJSValue JSC_HOST_CALL stringProtoFuncPadStart(ExecState*);
</ins><span class="cx"> EncodedJSValue JSC_HOST_CALL stringProtoFuncRepeat(ExecState*);
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL stringProtoFuncReplace(ExecState*);
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL stringProtoFuncSlice(ExecState*);
</span><span class="lines">@@ -133,6 +135,8 @@
</span><span class="cx"> JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("concat", stringProtoFuncConcat, DontEnum, 1);
</span><span class="cx"> JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("indexOf", stringProtoFuncIndexOf, DontEnum, 1);
</span><span class="cx"> JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("lastIndexOf", stringProtoFuncLastIndexOf, DontEnum, 1);
</span><ins>+ JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("padEnd", stringProtoFuncPadEnd, DontEnum, 1);
+ JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("padStart", stringProtoFuncPadStart, DontEnum, 1);
</ins><span class="cx"> JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("repeat", stringProtoFuncRepeat, DontEnum, 1);
</span><span class="cx"> JSC_NATIVE_INTRINSIC_FUNCTION_WITHOUT_TRANSITION("replace", stringProtoFuncReplace, DontEnum, 2, StringPrototypeReplaceIntrinsic);
</span><span class="cx"> JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("slice", stringProtoFuncSlice, DontEnum, 2);
</span><span class="lines">@@ -775,6 +779,39 @@
</span><span class="cx"> return jsString(exec, impl.release());
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+template <typename CharacterType>
+static inline JSString* repeatCharacter(ExecState& exec, CharacterType character, unsigned repeatCount)
+{
+ CharacterType* buffer = nullptr;
+ RefPtr<StringImpl> impl = StringImpl::tryCreateUninitialized(repeatCount, buffer);
+ if (!impl)
+ return throwOutOfMemoryError(&exec), nullptr;
+
+ std::fill_n(buffer, repeatCount, character);
+
+ return jsString(&exec, impl.release());
+}
+
+static inline bool repeatStringPattern(ExecState& exec, unsigned maxLength, JSString* string, JSRopeString::RopeBuilder& ropeBuilder)
+{
+ unsigned repeatCount = maxLength / string->length();
+ unsigned remainingCharacters = maxLength - repeatCount * string->length();
+ for (unsigned i = 0; i < repeatCount; ++i) {
+ if (!ropeBuilder.append(string)) {
+ throwOutOfMemoryError(&exec);
+ return false;
+ }
+ }
+ if (remainingCharacters) {
+ JSString* substr = jsSubstring(&exec, string, 0, remainingCharacters);
+ if (!substr || !ropeBuilder.append(substr)) {
+ throwOutOfMemoryError(&exec);
+ return false;
+ }
+ }
+ return true;
+}
+
</ins><span class="cx"> EncodedJSValue JSC_HOST_CALL stringProtoFuncRepeat(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> JSValue thisValue = exec->thisValue();
</span><span class="lines">@@ -822,6 +859,79 @@
</span><span class="cx"> return JSValue::encode(ropeBuilder.release());
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+enum class StringPaddingLocation { Start, End };
+
+static EncodedJSValue padString(ExecState& exec, StringPaddingLocation paddingLocation)
+{
+ JSValue thisValue = exec.thisValue();
+ if (!thisValue.requireObjectCoercible(&exec))
+ return JSValue::encode(jsUndefined());
+ JSString* thisString = thisValue.toString(&exec);
+ if (exec.hadException())
+ return JSValue::encode(jsUndefined());
+
+ double maxLengthAsDouble = exec.argument(0).toLength(&exec);
+ if (exec.hadException())
+ return JSValue::encode(jsUndefined());
+ ASSERT(maxLengthAsDouble >= 0.0);
+ ASSERT(maxLengthAsDouble == std::trunc(maxLengthAsDouble));
+
+ if (maxLengthAsDouble <= thisString->length())
+ return JSValue::encode(thisString);
+
+ if (maxLengthAsDouble > JSString::MaxLength)
+ return JSValue::encode(throwOutOfMemoryError(&exec));
+
+ unsigned maxLength = static_cast<unsigned>(maxLengthAsDouble);
+
+ JSValue fillString = exec.argument(1);
+ JSString* filler = nullptr;
+ if (!fillString.isUndefined()) {
+ filler = fillString.toString(&exec);
+ if (!filler)
+ return JSValue::encode(jsUndefined());
+ }
+
+ unsigned fillLength = static_cast<unsigned>(maxLength) - thisString->length();
+
+ JSRopeString::RopeBuilder ropeBuilder(exec.vm());
+ if (paddingLocation == StringPaddingLocation::End) {
+ if (!ropeBuilder.append(thisString))
+ return JSValue::encode(throwOutOfMemoryError(&exec));
+ }
+
+ if (!filler || filler->length() == 1) {
+ UChar character = filler ? filler->view(&exec)[0] : ' ';
+ if (!(character & ~0xff))
+ filler = repeatCharacter(exec, static_cast<LChar>(character), fillLength);
+ else
+ filler = repeatCharacter(exec, character, fillLength);
+ if (!filler || !ropeBuilder.append(filler))
+ return JSValue::encode(throwOutOfMemoryError(&exec));
+ ASSERT(filler->length() == fillLength);
+ } else {
+ if (!repeatStringPattern(exec, fillLength, filler, ropeBuilder))
+ return JSValue::encode(throwOutOfMemoryError(&exec));
+ }
+
+ if (paddingLocation == StringPaddingLocation::Start) {
+ if (!ropeBuilder.append(thisString))
+ return JSValue::encode(throwOutOfMemoryError(&exec));
+ }
+ ASSERT(!exec.hadException());
+ return JSValue::encode(ropeBuilder.release());
+}
+
+EncodedJSValue JSC_HOST_CALL stringProtoFuncPadEnd(ExecState* exec)
+{
+ return padString(*exec, StringPaddingLocation::End);
+}
+
+EncodedJSValue JSC_HOST_CALL stringProtoFuncPadStart(ExecState* exec)
+{
+ return padString(*exec, StringPaddingLocation::Start);
+}
+
</ins><span class="cx"> ALWAYS_INLINE EncodedJSValue replace(
</span><span class="cx"> ExecState* exec, JSString* string, JSValue searchValue, JSValue replaceValue)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestses6Stringprototype_methods_StringprototypepadEndjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/es6/String.prototype_methods_String.prototype.padEnd.js (0 => 198674)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/es6/String.prototype_methods_String.prototype.padEnd.js         (rev 0)
+++ trunk/Source/JavaScriptCore/tests/es6/String.prototype_methods_String.prototype.padEnd.js        2016-03-25 17:37:48 UTC (rev 198674)
</span><span class="lines">@@ -0,0 +1,107 @@
</span><ins>+function shouldBe(expected, actual, msg) {
+ if (msg === void 0)
+ msg = '';
+ else
+ msg = ' for ' + msg;
+ if (actual !== expected)
+ throw new Error('bad value' + msg + ': ' + actual + '. Expected ' + expected);
+}
+
+function shouldThrow(func, errorType) {
+ try {
+ func();
+ throw new Error('Expected ' + func + '() to throw ' + errorType.name + ', but did not throw.');
+ } catch (e) {
+ if (e instanceof errorType) return;
+ throw new Error('Expected ' + func + '() to throw ' + errorType.name + ', but threw ' + e);
+ }
+}
+
+(function TestMeta() {
+ shouldBe(1, String.prototype.padEnd.length);
+ shouldBe("function", typeof String.prototype.padEnd);
+ shouldBe(Object.getPrototypeOf(Function), Object.getPrototypeOf(String.prototype.padEnd));
+ shouldBe("padEnd", String.prototype.padEnd.name);
+
+ var descriptor = Object.getOwnPropertyDescriptor(String.prototype, "padEnd");
+ shouldBe(undefined, descriptor.get);
+ shouldBe(undefined, descriptor.set);
+ shouldBe(true, descriptor.configurable);
+ shouldBe(false, descriptor.enumerable);
+ shouldBe(true, descriptor.writable);
+ shouldBe(String.prototype.padEnd, descriptor.value);
+
+ shouldThrow(() => new Function(`${String.prototype.padEnd}`), SyntaxError);
+})();
+
+(function TestRequireObjectCoercible() {
+ var padEnd = String.prototype.padEnd;
+ shouldThrow(() => padEnd.call(null, 4, "test"), TypeError);
+ shouldThrow(() => padEnd.call(undefined, 4, "test"), TypeError);
+ shouldBe("123 ", padEnd.call({
+ __proto__: null,
+ valueOf() { return 123; }
+ }, 6, " "));
+
+ var proxy = new Proxy({}, {
+ get(t, name) {
+ if (name === Symbol.toPrimitive || name === "toString") return;
+ if (name === "valueOf") return () => 6.7;
+ throw new Error("unreachable code");
+ }
+ });
+ shouldBe("6.7 ", padEnd.call(proxy, 6, " "));
+
+ proxy = new Proxy({}, {
+ get(t, name) {
+ if (name === Symbol.toPrimitive || name === "valueOf") return;
+ if (name === "toString") return () => 6.7;
+ throw new Error("unreachable code");
+ }
+ });
+ shouldBe("6.7 ", padEnd.call(proxy, 6, " "));
+})();
+
+(function TestToLength() {
+ shouldThrow(() => "123".padEnd(Symbol("16")), TypeError);
+ shouldBe("123", "123".padEnd(-1));
+ shouldBe("123", "123".padEnd({ toString() { return -1; } }));
+ shouldBe("123", "123".padEnd(-0));
+ shouldBe("123", "123".padEnd({ toString() { return -0; } }));
+ shouldBe("123", "123".padEnd(+0));
+ shouldBe("123", "123".padEnd({ toString() { return +0; } }));
+ shouldBe("123", "123".padEnd(NaN));
+ shouldBe("123", "123".padEnd({ toString() { return NaN; } }));
+})();
+
+(function TestFillerToString() {
+ shouldBe(". ", ".".padEnd(10));
+ shouldBe(". ", ".".padEnd(10, undefined));
+ shouldBe(". ", ".".padEnd(10, { toString() { return ""; } }));
+ shouldBe(".nullnulln", ".".padEnd(10, null));
+})();
+
+(function TestSingleCharacterFiller() {
+ shouldBe(".!!!!!!!!!", ".".padEnd(10, "!"));
+ shouldBe(".!!!!!!!!!", ".".padEnd(10, { toString() { return "!"; } }));
+ shouldBe(".!!!!!!!!!", ".".padEnd(10, "" + "!" + ""));
+ shouldBe(".!!!!!!!!!", ".".padEnd(10, { toString() { return "" + "!" + ""; } }));
+})();
+
+(function TestMemoryLimits() {
+ shouldThrow(() => ".".padEnd(0x80000000, "o"), Error);
+ shouldThrow(() => ".".padEnd({ valueOf() { return 0x80000000; } }, "o"), Error);
+ shouldThrow(() => ".".padEnd("0x80000000", "o"), Error);
+})();
+
+(function TestFillerRepetition() {
+ for (var i = 2000; i > 0; --i) {
+ var expected = "123" + "xoxo".repeat(i / 4).slice(0, i - 3);
+ var actual = "123".padEnd(i, "xoxo");
+ shouldBe(expected, actual);
+ shouldBe(i > "123".length ? i : 3, actual.length);
+ actual = "123".padEnd(i, "xo" + "" + "xo");
+ shouldBe(expected, actual);
+ shouldBe(i > "123".length ? i : 3, actual.length);
+ }
+})();
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoretestses6Stringprototype_methods_StringprototypepadStartjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/es6/String.prototype_methods_String.prototype.padStart.js (0 => 198674)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/es6/String.prototype_methods_String.prototype.padStart.js         (rev 0)
+++ trunk/Source/JavaScriptCore/tests/es6/String.prototype_methods_String.prototype.padStart.js        2016-03-25 17:37:48 UTC (rev 198674)
</span><span class="lines">@@ -0,0 +1,107 @@
</span><ins>+function shouldBe(expected, actual, msg) {
+ if (msg === void 0)
+ msg = '';
+ else
+ msg = ' for ' + msg;
+ if (actual !== expected)
+ throw new Error('bad value' + msg + ': ' + actual + '. Expected ' + expected);
+}
+
+function shouldThrow(func, errorType) {
+ try {
+ func();
+ throw new Error('Expected ' + func + '() to throw ' + errorType.name + ', but did not throw.');
+ } catch (e) {
+ if (e instanceof errorType) return;
+ throw new Error('Expected ' + func + '() to throw ' + errorType.name + ', but threw ' + e);
+ }
+}
+
+(function TestMeta() {
+ shouldBe(1, String.prototype.padEnd.length);
+ shouldBe("function", typeof String.prototype.padStart);
+ shouldBe(Object.getPrototypeOf(Function), Object.getPrototypeOf(String.prototype.padStart));
+ shouldBe("padStart", String.prototype.padStart.name);
+
+ var descriptor = Object.getOwnPropertyDescriptor(String.prototype, "padStart");
+ shouldBe(undefined, descriptor.get);
+ shouldBe(undefined, descriptor.set);
+ shouldBe(true, descriptor.configurable);
+ shouldBe(false, descriptor.enumerable);
+ shouldBe(true, descriptor.writable);
+ shouldBe(String.prototype.padStart, descriptor.value);
+
+ shouldThrow(() => new Function(`${String.prototype.padStart}`), SyntaxError);
+})();
+
+(function TestRequireObjectCoercible() {
+ var padStart = String.prototype.padStart;
+ shouldThrow(() => padStart.call(null, 4, "test"), TypeError);
+ shouldThrow(() => padStart.call(undefined, 4, "test"), TypeError);
+ shouldBe(" 123", padStart.call({
+ __proto__: null,
+ valueOf() { return 123; }
+ }, 6, " "));
+
+ var proxy = new Proxy({}, {
+ get(t, name) {
+ if (name === Symbol.toPrimitive || name === "toString") return;
+ if (name === "valueOf") return () => 6.7;
+ throw new Error("unreachable code");
+ }
+ });
+ shouldBe(" 6.7", padStart.call(proxy, 6, " "));
+
+ proxy = new Proxy({}, {
+ get(t, name) {
+ if (name === Symbol.toPrimitive || name === "valueOf") return;
+ if (name === "toString") return () => 6.7;
+ throw new Error("unreachable code");
+ }
+ });
+ shouldBe(" 6.7", padStart.call(proxy, 6, " "));
+})();
+
+(function TestToLength() {
+ shouldThrow(() => "123".padStart(Symbol("16")), TypeError);
+ shouldBe("123", "123".padStart(-1));
+ shouldBe("123", "123".padStart({ toString() { return -1; } }));
+ shouldBe("123", "123".padStart(-0));
+ shouldBe("123", "123".padStart({ toString() { return -0; } }));
+ shouldBe("123", "123".padStart(+0));
+ shouldBe("123", "123".padStart({ toString() { return +0; } }));
+ shouldBe("123", "123".padStart(NaN));
+ shouldBe("123", "123".padStart({ toString() { return NaN; } }));
+})();
+
+(function TestFillerToString() {
+ shouldBe(" .", ".".padStart(10));
+ shouldBe(" .", ".".padStart(10, undefined));
+ shouldBe(" .", ".".padStart(10, { toString() { return ""; } }));
+ shouldBe("nullnulln.", ".".padStart(10, null));
+})();
+
+(function TestSingleCharacterFiller() {
+ shouldBe("!!!!!!!!!.", ".".padStart(10, "!"));
+ shouldBe("!!!!!!!!!.", ".".padStart(10, { toString() { return "!"; } }));
+ shouldBe("!!!!!!!!!.", ".".padStart(10, "" + "!" + ""));
+ shouldBe("!!!!!!!!!.", ".".padStart(10, { toString() { return "" + "!" + ""; } }));
+})();
+
+(function TestMemoryLimits() {
+ shouldThrow(() => ".".padStart(0x80000000, "o"), Error);
+ shouldThrow(() => ".".padStart({ valueOf() { return 0x80000000; } }, "o"), Error);
+ shouldThrow(() => ".".padStart("0x80000000", "o"), Error);
+})();
+
+(function TestFillerRepetition() {
+ for (var i = 2000; i > 0; --i) {
+ var expected = "xoxo".repeat(i / 4).slice(0, i - 3) + "123";
+ var actual = "123".padStart(i, "xoxo");
+ shouldBe(expected, actual);
+ shouldBe(i > "123".length ? i : 3, actual.length);
+ actual = "123".padStart(i, "xo" + "" + "xo");
+ shouldBe(expected, actual);
+ shouldBe(i > "123".length ? i : 3, actual.length);
+ }
+})();
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoretestses6yaml"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/tests/es6.yaml (198673 => 198674)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/es6.yaml        2016-03-25 17:24:33 UTC (rev 198673)
+++ trunk/Source/JavaScriptCore/tests/es6.yaml        2016-03-25 17:37:48 UTC (rev 198674)
</span><span class="lines">@@ -574,6 +574,10 @@
</span><span class="cx"> cmd: runES6 :normal
</span><span class="cx"> - path: es6/String.prototype_methods_String.prototype.normalize.js
</span><span class="cx"> cmd: runES6 :normal
</span><ins>+- path: es6/String.prototype_methods_String.prototype.padEnd.js
+ cmd: runES6 :normal
+- path: es6/String.prototype_methods_String.prototype.padStart.js
+ cmd: runES6 :normal
</ins><span class="cx"> - path: es6/String.prototype_methods_String.prototype.repeat.js
</span><span class="cx"> cmd: runES6 :normal
</span><span class="cx"> - path: es6/String.prototype_methods_String.prototype.startsWith.js
</span></span></pre>
</div>
</div>
</body>
</html>