Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Allow RegExp to String coercion
Browse files Browse the repository at this point in the history
Closes #3
  • Loading branch information
littledan authored and ljharb committed Apr 25, 2017
1 parent 0e0d313 commit e35d0ed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
45 changes: 25 additions & 20 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2164,8 +2164,13 @@ <h1><span class="secnum">1</span>String.prototype.matchAll ( <var>regexp</var> )
</li>
</ol>
</li>
<li>Throw a
<emu-val>TypeError</emu-val> exception.
<li>Let <var>S</var> be ?
<emu-xref aoid="ToString" id="_ref_7"><a href="https://tc39.github.io/ecma262/#sec-tostring">ToString</a></emu-xref>(<var>O</var>).</li>
<li>Let <var>rx</var> be ?
<emu-xref aoid="RegExpCreate" id="_ref_8"><a href="https://tc39.github.io/ecma262/#sec-regexpcreate">RegExpCreate</a></emu-xref>(<var>regexp</var>,
<emu-val>undefined</emu-val>).</li>
<li>Return ?
<emu-xref aoid="Invoke" id="_ref_9"><a href="https://tc39.github.io/ecma262/#sec-invoke">Invoke</a></emu-xref>(<var>rx</var>, @@matchAll, « <var>S</var> »).
</li>
</ol>
</emu-alg>
Expand All @@ -2182,32 +2187,32 @@ <h1><span class="secnum">2</span>RegExp.prototype [ @@matchAll ] ( <var>string</
<li>Let <var>rx</var> be the
<emu-val>this</emu-val> value.</li>
<li>If
<emu-xref aoid="Type" id="_ref_7"><a href="https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(<var>rx</var>) is not Object, throw a
<emu-xref aoid="Type" id="_ref_10"><a href="https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(<var>rx</var>) is not Object, throw a
<emu-val>TypeError</emu-val> exception.</li>
<li>Let <var>S</var> be ?
<emu-xref aoid="ToString" id="_ref_8"><a href="https://tc39.github.io/ecma262/#sec-tostring">ToString</a></emu-xref>(<var>string</var>).</li>
<emu-xref aoid="ToString" id="_ref_11"><a href="https://tc39.github.io/ecma262/#sec-tostring">ToString</a></emu-xref>(<var>string</var>).</li>
<li>Let <var>C</var> be ?
<emu-xref aoid="SpeciesConstructor" id="_ref_9"><a href="https://tc39.github.io/ecma262/#sec-speciesconstructor">SpeciesConstructor</a></emu-xref>(<var>rx</var>,
<emu-xref aoid="SpeciesConstructor" id="_ref_12"><a href="https://tc39.github.io/ecma262/#sec-speciesconstructor">SpeciesConstructor</a></emu-xref>(<var>rx</var>,
<emu-xref href="#sec-regexp-constructor"><a href="https://tc39.github.io/ecma262/#sec-regexp-constructor">%RegExp%</a></emu-xref>).</li>
<li>Let <var>flags</var> be ?
<emu-xref aoid="ToString" id="_ref_10"><a href="https://tc39.github.io/ecma262/#sec-tostring">ToString</a></emu-xref>(?
<emu-xref aoid="Get" id="_ref_11"><a href="https://tc39.github.io/ecma262/#sec-get-o-p">Get</a></emu-xref>(<var>rx</var>, <code>"flags"</code>)).</li>
<emu-xref aoid="ToString" id="_ref_13"><a href="https://tc39.github.io/ecma262/#sec-tostring">ToString</a></emu-xref>(?
<emu-xref aoid="Get" id="_ref_14"><a href="https://tc39.github.io/ecma262/#sec-get-o-p">Get</a></emu-xref>(<var>rx</var>, <code>"flags"</code>)).</li>
<li>If <var>flags</var> contains <code>"g"</code>, let <var>newFlags</var> be <var>flags</var>.</li>
<li>Else, let <var>newFlags</var> be the string that is the concatenation of <var>flags</var> and <code>"g"</code>.</li>
<li>Let <var>matcher</var> be ?
<emu-xref aoid="Construct" id="_ref_12"><a href="https://tc39.github.io/ecma262/#sec-construct">Construct</a></emu-xref>(<var>C</var>, « <var>rx</var>, <var>newFlags</var> »).</li>
<emu-xref aoid="Construct" id="_ref_15"><a href="https://tc39.github.io/ecma262/#sec-construct">Construct</a></emu-xref>(<var>C</var>, « <var>rx</var>, <var>newFlags</var> »).</li>
<li>Let <var>lastIndex</var> be
<emu-xref aoid="ToLength" id="_ref_13"><a href="https://tc39.github.io/ecma262/#sec-tolength">ToLength</a></emu-xref>(
<emu-xref aoid="Get" id="_ref_14"><a href="https://tc39.github.io/ecma262/#sec-get-o-p">Get</a></emu-xref>(<var>rx</var>,
<emu-xref aoid="ToLength" id="_ref_16"><a href="https://tc39.github.io/ecma262/#sec-tolength">ToLength</a></emu-xref>(
<emu-xref aoid="Get" id="_ref_17"><a href="https://tc39.github.io/ecma262/#sec-get-o-p">Get</a></emu-xref>(<var>rx</var>,
<emu-val>"lastIndex"</emu-val>)).</li>
<li>
<emu-xref aoid="ReturnIfAbrupt" id="_ref_15"><a href="https://tc39.github.io/ecma262/#sec-returnifabrupt">ReturnIfAbrupt</a></emu-xref>(<var>lastIndex</var>).</li>
<emu-xref aoid="ReturnIfAbrupt" id="_ref_18"><a href="https://tc39.github.io/ecma262/#sec-returnifabrupt">ReturnIfAbrupt</a></emu-xref>(<var>lastIndex</var>).</li>
<li>Let <var>setStatus</var> be
<emu-xref aoid="Set" id="_ref_16"><a href="https://tc39.github.io/ecma262/#sec-set-o-p-v-throw">Set</a></emu-xref>(<var>matcher</var>,
<emu-xref aoid="Set" id="_ref_19"><a href="https://tc39.github.io/ecma262/#sec-set-o-p-v-throw">Set</a></emu-xref>(<var>matcher</var>,
<emu-val>"lastIndex"</emu-val>, <var>lastIndex</var>,
<emu-val>true</emu-val>).</li>
<li>
<emu-xref aoid="ReturnIfAbrupt" id="_ref_17"><a href="https://tc39.github.io/ecma262/#sec-returnifabrupt">ReturnIfAbrupt</a></emu-xref>(<var>setStatus</var>).</li>
<emu-xref aoid="ReturnIfAbrupt" id="_ref_20"><a href="https://tc39.github.io/ecma262/#sec-returnifabrupt">ReturnIfAbrupt</a></emu-xref>(<var>setStatus</var>).</li>
<li>Return CreateRegExpStringIterator(<var>matcher</var>, <var>S</var>)
</li>
</ol>
Expand All @@ -2221,9 +2226,9 @@ <h1><span class="secnum">3</span>CreateRegExpStringIterator ( <var>regexp</var>,
<emu-alg>
<ol>
<li>Assert:
<emu-xref aoid="Type" id="_ref_18"><a href="https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(<var>S</var>) is String.</li>
<emu-xref aoid="Type" id="_ref_21"><a href="https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(<var>S</var>) is String.</li>
<li>Let <var>iterator</var> be
<emu-xref aoid="ObjectCreate" id="_ref_19"><a href="https://tc39.github.io/ecma262/#sec-objectcreate">ObjectCreate</a></emu-xref>(
<emu-xref aoid="ObjectCreate" id="_ref_22"><a href="https://tc39.github.io/ecma262/#sec-objectcreate">ObjectCreate</a></emu-xref>(
<emu-xref href="#%RegExpStringIteratorPrototype%" id="_ref_0"><a href="#%RegExpStringIteratorPrototype%">%RegExpStringIteratorPrototype%</a></emu-xref>, «[[IteratingRegExp]], [[IteratedString]]»).</li>
<li>Set <var>iterator</var>.[[IteratingRegExp]] to <var>R</var>.</li>
<li>Set <var>iterator</var>.[[IteratedString]] to <var>S</var>.</li>
Expand All @@ -2246,28 +2251,28 @@ <h1><span class="secnum">4.1</span>%RegExpStringIteratorPrototype%.next ( )</h1>
<li>Let <var>O</var> be the
<emu-val>this</emu-val> value.</li>
<li>If
<emu-xref aoid="Type" id="_ref_20"><a href="https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(<var>O</var>) is not Object, throw a
<emu-xref aoid="Type" id="_ref_23"><a href="https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(<var>O</var>) is not Object, throw a
<emu-val>TypeError</emu-val> exception.</li>
<li>If <var>O</var> does not have all of the internal slots of a RegExp String Iterator Object Instance (see
<emu-xref href="#PropertiesOfRegExpStringIteratorInstances" id="_ref_2"><a href="#PropertiesOfRegExpStringIteratorInstances">4.3</a></emu-xref>), throw a
<emu-val>TypeError</emu-val> exception.</li>
<li>Let <var>regexp</var> be <var>O</var>.[[IteratingRegExp]].</li>
<li>Let <var>string</var> be <var>O</var>.[[IteratedString]].</li>
<li>Let <var>match</var> be
<emu-xref aoid="RegExpExec" id="_ref_21"><a href="https://tc39.github.io/ecma262/#sec-regexpexec">RegExpExec</a></emu-xref>(<var>regexp</var>, <var>string</var>)</li>
<emu-xref aoid="RegExpExec" id="_ref_24"><a href="https://tc39.github.io/ecma262/#sec-regexpexec">RegExpExec</a></emu-xref>(<var>regexp</var>, <var>string</var>)</li>
<li>If <var>match</var> is
<emu-val>null</emu-val>, then
<ol>
<li>Return
<emu-xref aoid="CreateIterResultObject" id="_ref_22"><a href="https://tc39.github.io/ecma262/#sec-createiterresultobject">CreateIterResultObject</a></emu-xref>(
<emu-xref aoid="CreateIterResultObject" id="_ref_25"><a href="https://tc39.github.io/ecma262/#sec-createiterresultobject">CreateIterResultObject</a></emu-xref>(
<emu-val>null</emu-val>,
<emu-val>true</emu-val>).</li>
</ol>
</li>
<li>Otherwise,
<ol>
<li>Return
<emu-xref aoid="CreateIterResultObject" id="_ref_23"><a href="https://tc39.github.io/ecma262/#sec-createiterresultobject">CreateIterResultObject</a></emu-xref>(<var>match</var>,
<emu-xref aoid="CreateIterResultObject" id="_ref_26"><a href="https://tc39.github.io/ecma262/#sec-createiterresultobject">CreateIterResultObject</a></emu-xref>(<var>match</var>,
<emu-val>false</emu-val>).
</li>
</ol>
Expand Down Expand Up @@ -2301,7 +2306,7 @@ <h1><span class="secnum">4.3</span>Properties of RegExp String Iterator Instance
<tr>
<td>[[IteratingRegExp]]</td>
<td>The regular expression used for iteration.
<emu-xref aoid="IsRegExp" id="_ref_24"><a href="https://tc39.github.io/ecma262/#sec-isregexp">IsRegExp</a></emu-xref>([[IteratingRegExp]]) is always
<emu-xref aoid="IsRegExp" id="_ref_27"><a href="https://tc39.github.io/ecma262/#sec-isregexp">IsRegExp</a></emu-xref>([[IteratingRegExp]]) is always
<emu-val>true</emu-val>.</td>
</tr>
<tr>
Expand Down
4 changes: 3 additions & 1 deletion spec.emu
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ contributors: Jordan Harband
1. Let _matcher_ be ? GetMethod(_regexp_, @@matchAll).
1. If _matcher_ is not *undefined*, then
1. Return ? Call(_matcher_, _regexp_, &laquo; _O_ &raquo;).
1. Throw a *TypeError* exception.
1. Let _S_ be ? ToString(_O_).
1. Let _rx_ be ? RegExpCreate(_regexp_, *undefined*).
1. Return ? Invoke(_rx_, @@matchAll, &laquo; _S_ &raquo;).
</emu-alg>
<emu-note>Similarly to String.prototype.split, String.prototype.matchAll is designed to typically act without mutating its inputs.</emu-note>
</emu-clause>
Expand Down

0 comments on commit e35d0ed

Please sign in to comment.