Skip to content

Commit

Permalink
Add RegExp.prototype[@@matchall]
Browse files Browse the repository at this point in the history
Additionally, modernize spec text generally

Closes tc39#2
  • Loading branch information
littledan authored and ljharb committed Apr 25, 2017
1 parent bf5e427 commit 2ba7c85
Showing 1 changed file with 33 additions and 30 deletions.
63 changes: 33 additions & 30 deletions spec.emu
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
<link rel="stylesheet" href="./spec.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css" />
<script src="./spec.js"></script>
<pre class="metadata">
title: String.prototype.matchAll
stage: 1
contributors: Jordan Harband
</pre>
<emu-clause id="String.prototype.matchAll">
<h1>String.prototype.matchAll ( _regexp_ )</h1>
<emu-note>_matchAll_ does not visibly mutate the provided _regexp_ in any way.</emu-note>
<p>When the _matchAll_ method is called, the following steps are taken:</p>
<emu-alg>
1. Let _O_ be RequireObjectCoercible(*this* value).
1. Let _isRegExp_ be IsRegExp(_regexp_).
1. ReturnIfAbrupt(_isRegExp_).
1. If _isRegExp_ is *false*, throw a *TypeError* exception.
1. Let _S_ be ToString(*O*).
1. ReturnIfAbrupt(_S_).
1. Let _flags_ be ToString(Get(regexp, *"flags"*)).
1. ReturnIfAbrupt(_flags_).
1. If _flags_ does not contain the character *"g"*, let _flags_ be the String concatenation of the String *"g"* and _flags_.
1. Let _rx_ be RegExpCreate(_regexp_, _flags_).
1. Let _lastIndex_ be ToLength(Get(regexp, *"lastIndex"*)).
1. Let _O_ be ? RequireObjectCoercible(*this* value).
1. If _regexp_ is neither *undefined* nor *null*, then
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.
</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>

<emu-clause id="RegExp.prototype[@@matchAll]">
<h1>RegExp.prototype [ @@matchAll ] ( _string_ )</h1>
<p>When the `@@matchAll` method is called, the following steps are taken:</p>
<emu-alg>
1. Let _rx_ be the *this* value.
1. If Type(_rx_) is not Object, throw a *TypeError* exception.
1. Let _S_ be ? ToString(_string_).
1. Let _C_ be ? SpeciesConstructor(_rx_, %RegExp%).
1. Let _flags_ be ? ToString(? Get(_rx_, `"flags"`)).
1. If _flags_ contains `"g"`, let _newFlags_ be _flags_.
1. Else, let _newFlags_ be the string that is the concatenation of _flags_ and `"g"`.
1. Let _matcher_ be ? Construct(_C_, &laquo; _rx_, _newFlags_ &raquo;).
1. Let _lastIndex_ be ToLength(Get(_rx_, *"lastIndex"*)).
1. ReturnIfAbrupt(_lastIndex_).
1. Let _setStatus_ be Set(_rx_, *"lastIndex"*, _lastIndex_, *true*).
1. Let _setStatus_ be Set(_matcher_, *"lastIndex"*, _lastIndex_, *true*).
1. ReturnIfAbrupt(_setStatus_).
1. Return CreateRegExpStringIterator(_rx_, _S_)
1. Return CreateRegExpStringIterator(_matcher_, _S_)
</emu-alg>
<p>The _length_ property of the _matchAll_ method is *1*.</p>
<emu-note>The _rx_ regular expression value is created solely to ensure that no visible mutation happens on _regexp_ - it should never be exposed to the environment.</emu-note>
</emu-clause>

<emu-clause id="CreateRegExpStringIterator">
<h1>CreateRegExpStringIterator( _regexp_, _string_ )</h1>

<p>The abstract operation CreateRegExpStringIterator is used to create such iterator objects. It performs the following steps:</p>
<emu-alg>
1. Assert: IsRegExp(_R_) is *true*.
1. Assert: ToBoolean(Get(_R_, *"global"*)) is *true*.
1. Assert: Type(_S_) is String.
1. Let _iterator_ be ObjectCreate(<emu-xref href="#%RegExpStringIteratorPrototype%">%RegExpStringIteratorPrototype%</emu-xref>, &laquo; [[IteratingRegExp]], [[IteratedString]] &raquo;).
1. Set _iterator's_ [[IteratingRegExp]] <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-object-internal-methods-and-internal-slots">internal slot</a> to _R_.
1. Set _iterator's_ [[IteratedString]] <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-object-internal-methods-and-internal-slots">internal slot</a> to _S_.
1. Let _iterator_ be ObjectCreate(<emu-xref href="#%RegExpStringIteratorPrototype%">%RegExpStringIteratorPrototype%</emu-xref>, «[[IteratingRegExp]], [[IteratedString]]»).
1. Set _iterator_.[[IteratingRegExp]] to _R_.
1. Set _iterator_.[[IteratedString]] to _S_.
1. Return _iterator_.
</emu-alg>
</emu-clause>
Expand All @@ -57,15 +61,14 @@ contributors: Jordan Harband
1. Let _O_ be the *this* value.
1. If Type(_O_) is not Object, throw a *TypeError* exception.
1. If _O_ does not have all of the internal slots of a RegExp String Iterator Object Instance (see <emu-xref href="#PropertiesOfRegExpStringIteratorInstances"></emu-xref>), throw a *TypeError* exception.
1. Let _regexp_ be the value of the [[IteratingRegExp]] <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-object-internal-methods-and-internal-slots">internal slot</a> of _O_.
1. Let _string_ be the value of the [[IteratedString]] <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-object-internal-methods-and-internal-slots">internal slot</a> of _O_.
1. Let _regexp_ be _O_.[[IteratingRegExp]].
1. Let _string_ be _O_.[[IteratedString]].
1. Let _match_ be RegExpExec(_regexp_, _string_)
1. If _match_ is *null*, then
1. return CreateIterResultObject(*null*, *true*).
1. Else,
1. return CreateIterResultObject(_match_, *false*).
1. Return CreateIterResultObject(*null*, *true*).
1. Otherwise,
1. Return CreateIterResultObject(_match_, *false*).
</emu-alg>
<p>The _length_ property of the `next` method is *0*.</p>
</emu-clause>

<emu-clause id="%RegExpStringIteratorPrototype%[@@toStringTag]">
Expand Down

0 comments on commit 2ba7c85

Please sign in to comment.