Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Commit

Permalink
Use concise ReturnIfAbrupt syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 3, 2015
1 parent 1790cff commit fd0ec3a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 43 deletions.
24 changes: 9 additions & 15 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,22 @@
</ol>
</div>
</div>
<h1 class="version">Stage 1 Draft / October 28, 2015</h1>
<h1 class="version">Stage 1 Draft / November 3, 2015</h1>
<h1 class="title">String.prototype.padLeft / padRight</h1>
<emu-clause id="String.prototype.padLeft">
<h1><span class="secnum">1</span>String.prototype.padLeft( maxLength [ , fillString ] )<span class="utils"><span class="anchor"><a href="#String.prototype.padLeft">#</a></span></span></h1>
<p>When the <code>padLeft</code> method is called, the following steps are taken:</p>
<emu-alg>
<ol>
<li>Let <var>O</var> be <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-requireobjectcoercible">RequireObjectCoercible</a>(
<li>Let <var>O</var> be ? <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-requireobjectcoercible">RequireObjectCoercible</a>(
<emu-val>this</emu-val> value).</li>
<li>Let <var>S</var> be <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-tostring">ToString</a>(<var>O</var>).</li>
<li><a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-returnifabrupt">ReturnIfAbrupt</a>(<var>S</var>).</li>
<li>Let <var>intMaxLength</var> be <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-tolength">ToLength</a>(<var>maxLength</var>).</li>
<li><a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-returnifabrupt">ReturnIfAbrupt</a>(<var>intMaxLength</var>).</li>
<li>Let <var>S</var> be ? <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-tostring">ToString</a>(<var>O</var>).</li>
<li>Let <var>intMaxLength</var> be ? <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-tolength">ToLength</a>(<var>maxLength</var>).</li>
<li>Let <var>stringLength</var> be the number of elements in S.</li>
<li>If <var>intMaxLength</var> is not greater than <var>stringLength</var>, return <var>S</var>.</li>
<li>If <var>fillString</var> is
<emu-val>undefined</emu-val>, let <var>filler</var> be the empty String.</li>
<li>Else, let <var>filler</var> be <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-tostring">ToString</a>(<var>fillString</var>).</li>
<li><a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-returnifabrupt">ReturnIfAbrupt</a>(<var>filler</var>).</li>
<li>Else, let <var>filler</var> be ? <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-tostring">ToString</a>(<var>fillString</var>).</li>
<li>If <var>filler</var> is the empty String, let <var>filler</var> be a string consisting solely of the code unit U+0020 (SPACE).</li>
<li>Let <var>fillLen</var> be <var>intMaxLength</var> - <var>stringLength</var>.</li>
<li>Let <var>truncatedStringFiller</var> be a new String value consisting of repeated concatenations of <var>filler</var> truncated to length <var>fillLen</var>.</li>
Expand All @@ -62,18 +59,15 @@ <h1><span class="secnum">2</span>String.prototype.padRight( maxLength [ , fillSt
<p>When the <code>padRight</code> method is called, the following steps are taken:</p>
<emu-alg>
<ol>
<li>Let <var>O</var> be <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-requireobjectcoercible">RequireObjectCoercible</a>(
<li>Let <var>O</var> be ? <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-requireobjectcoercible">RequireObjectCoercible</a>(
<emu-val>this</emu-val> value).</li>
<li>Let <var>S</var> be <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-tostring">ToString</a>(<var>O</var>).</li>
<li><a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-returnifabrupt">ReturnIfAbrupt</a>(<var>S</var>).</li>
<li>Let <var>intMaxLength</var> be <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-tolength">ToLength</a>(<var>maxLength</var>).</li>
<li><a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-returnifabrupt">ReturnIfAbrupt</a>(<var>intMaxLength</var>).</li>
<li>Let <var>S</var> be ? <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-tostring">ToString</a>(<var>O</var>).</li>
<li>Let <var>intMaxLength</var> be ? <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-tolength">ToLength</a>(<var>maxLength</var>).</li>
<li>Let <var>stringLength</var> be the number of elements in S.</li>
<li>If <var>intMaxLength</var> is not greater than <var>stringLength</var>, return <var>S</var>.</li>
<li>If <var>fillString</var> is
<emu-val>undefined</emu-val>, let <var>filler</var> be the empty String.</li>
<li>Else, let <var>filler</var> be <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-tostring">ToString</a>(<var>fillString</var>).</li>
<li><a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-returnifabrupt">ReturnIfAbrupt</a>(<var>filler</var>).</li>
<li>Else, let <var>filler</var> be ? <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-tostring">ToString</a>(<var>fillString</var>).</li>
<li>If <var>filler</var> is the empty String, let <var>filler</var> be a string consisting solely of the code unit U+0020 (SPACE).</li>
<li>Let <var>fillLen</var> be <var>intMaxLength</var> - <var>stringLength</var>.</li>
<li>Let <var>truncatedStringFiller</var> be a new String value consisting of repeated concatenations of <var>filler</var> truncated to length <var>fillLen</var>.</li>
Expand Down
22 changes: 8 additions & 14 deletions spec.emu
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ contributors: Jordan Harband
<h1>String.prototype.padLeft( maxLength [ , fillString ] )</h1>
<p>When the `padLeft` method is called, the following steps are taken:</p>
<emu-alg>
1. Let _O_ be RequireObjectCoercible(*this* value).
1. Let _S_ be ToString(_O_).
1. ReturnIfAbrupt(_S_).
1. Let _intMaxLength_ be ToLength(_maxLength_).
1. ReturnIfAbrupt(_intMaxLength_).
1. Let _O_ be ? RequireObjectCoercible(*this* value).
1. Let _S_ be ? ToString(_O_).
1. Let _intMaxLength_ be ? ToLength(_maxLength_).
1. Let _stringLength_ be the number of elements in S.
1. If _intMaxLength_ is not greater than _stringLength_, return _S_.
1. If _fillString_ is *undefined*, let _filler_ be the empty String.
1. Else, let _filler_ be ToString(_fillString_).
1. ReturnIfAbrupt(_filler_).
1. Else, let _filler_ be ? ToString(_fillString_).
1. If _filler_ is the empty String, let _filler_ be a string consisting solely of the code unit U+0020 (SPACE).
1. Let _fillLen_ be _intMaxLength_ - _stringLength_.
1. Let _truncatedStringFiller_ be a new String value consisting of repeated concatenations of _filler_ truncated to length _fillLen_.
Expand All @@ -36,16 +33,13 @@ contributors: Jordan Harband
<h1>String.prototype.padRight( maxLength [ , fillString ] )</h1>
<p>When the `padRight` method is called, the following steps are taken:</p>
<emu-alg>
1. Let _O_ be RequireObjectCoercible(*this* value).
1. Let _S_ be ToString(_O_).
1. ReturnIfAbrupt(_S_).
1. Let _intMaxLength_ be ToLength(_maxLength_).
1. ReturnIfAbrupt(_intMaxLength_).
1. Let _O_ be ? RequireObjectCoercible(*this* value).
1. Let _S_ be ? ToString(_O_).
1. Let _intMaxLength_ be ? ToLength(_maxLength_).
1. Let _stringLength_ be the number of elements in S.
1. If _intMaxLength_ is not greater than _stringLength_, return _S_.
1. If _fillString_ is *undefined*, let _filler_ be the empty String.
1. Else, let _filler_ be ToString(_fillString_).
1. ReturnIfAbrupt(_filler_).
1. Else, let _filler_ be ? ToString(_fillString_).
1. If _filler_ is the empty String, let _filler_ be a string consisting solely of the code unit U+0020 (SPACE).
1. Let _fillLen_ be _intMaxLength_ - _stringLength_.
1. Let _truncatedStringFiller_ be a new String value consisting of repeated concatenations of _filler_ truncated to length _fillLen_.
Expand Down
22 changes: 8 additions & 14 deletions spec.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# String.prototype.padLeft( maxLength [ , fillString ] )

When the _padLeft_ method is called, the following steps are taken:
1. Let _O_ be RequireObjectCoercible(*this* value).
1. Let _S_ be ToString(_O_).
1. ReturnIfAbrupt(_S_).
1. Let _intMaxLength_ be ToLength(_maxLength_).
1. ReturnIfAbrupt(_intMaxLength_).
1. Let _O_ be ? RequireObjectCoercible(*this* value).
1. Let _S_ be ? ToString(_O_).
1. Let _intMaxLength_ be ? ToLength(_maxLength_).
1. Let _stringLength_ be the number of elements in S.
1. If _intMaxLength_ is not greater than _stringLength_, return _S_.
1. If _fillString_ is *undefined*, let _filler_ be the empty String.
1. Else, let _filler_ be ToString(_fillString_).
1. ReturnIfAbrupt(_filler_).
1. Else, let _filler_ be ? ToString(_fillString_).
1. If _filler_ is the empty String, let _filler_ be a string consisting solely of the code unit U+0020 (SPACE).
1. Let _fillLen_ be _intMaxLength_ - _stringLength_.
1. Let _truncatedStringFiller_ be a new String value consisting of repeated concatenations of _filler_ truncated to length _fillLen_.
Expand All @@ -22,16 +19,13 @@ Note: The optional second argument _fillString_ defaults to *" "* (a string cons
# String.prototype.padRight( maxLength [ , fillString ] )

When the _padRight_ method is called, the following steps are taken:
1. Let _O_ be RequireObjectCoercible(*this* value).
1. Let _S_ be ToString(_O_).
1. ReturnIfAbrupt(_S_).
1. Let _intMaxLength_ be ToLength(_maxLength_).
1. ReturnIfAbrupt(_intMaxLength_).
1. Let _O_ be ? RequireObjectCoercible(*this* value).
1. Let _S_ be ? ToString(_O_).
1. Let _intMaxLength_ be ? ToLength(_maxLength_).
1. Let _stringLength_ be the number of elements in S.
1. If _intMaxLength_ is not greater than _stringLength_, return _S_.
1. If _fillString_ is *undefined*, let _filler_ be the empty String.
1. Else, let _filler_ be ToString(_fillString_).
1. ReturnIfAbrupt(_filler_).
1. Else, let _filler_ be ? ToString(_fillString_).
1. If _filler_ is the empty String, let _filler_ be a string consisting solely of the code unit U+0020 (SPACE).
1. Let _fillLen_ be _intMaxLength_ - _stringLength_.
1. Let _truncatedStringFiller_ be a new String value consisting of repeated concatenations of _filler_ truncated to length _fillLen_.
Expand Down

0 comments on commit fd0ec3a

Please sign in to comment.