From af5190246abe13fe2284a4cfb7157c5f4e4a5c50 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 14 Dec 2017 00:08:31 -0800 Subject: [PATCH] Remove PreviousIndex checking; ensure only `global` creates multiple matches Per https://github.com/tc39/proposal-string-matchall/pull/29#discussion_r156234534 --- index.html | 14 +++++--------- spec.emu | 20 ++++---------------- spec.md | 20 ++++---------------- 3 files changed, 13 insertions(+), 41 deletions(-) diff --git a/index.html b/index.html index 99f0181..1cb8574 100644 --- a/index.html +++ b/index.html @@ -2207,7 +2207,7 @@
-

Stage 2 Draft / November 22, 2017

+

Stage 2 Draft / December 14, 2017

String.prototype.matchAll

@@ -2250,7 +2250,7 @@

3MatchAllIterator ( R, O )

4CreateRegExpStringIterator ( R, S, global, fullUnicode )

The abstract operation CreateRegExpStringIterator is used to create such iterator objects. It performs the following steps:

-
  1. Assert: Type(S) is String.
  2. Assert: Type(global) is Boolean.
  3. Assert: Type(fullUnicode) is Boolean.
  4. Let iterator be ObjectCreate(%RegExpStringIteratorPrototype%, « [[IteratingRegExp]], [[IteratedString]], [[PreviousIndex]], [[Done]] »).
  5. Set iterator.[[IteratingRegExp]] to R.
  6. Set iterator.[[IteratedString]] to S.
  7. Set iterator.[[Global]] to global.
  8. Set iterator.[[Unicode]] to fullUnicode.
  9. Set iterator.[[PreviousIndex]] to -1.
  10. Set iterator.[[Done]] to false.
  11. Return iterator. +
    1. Assert: Type(S) is String.
    2. Assert: Type(global) is Boolean.
    3. Assert: Type(fullUnicode) is Boolean.
    4. Let iterator be ObjectCreate(%RegExpStringIteratorPrototype%, « [[IteratingRegExp]], [[IteratedString]], [[Done]] »).
    5. Set iterator.[[IteratingRegExp]] to R.
    6. Set iterator.[[IteratedString]] to S.
    7. Set iterator.[[Global]] to global.
    8. Set iterator.[[Unicode]] to fullUnicode.
    9. Set iterator.[[Done]] to false.
    10. Return iterator.
    @@ -2263,8 +2263,8 @@

    5The %RegExpStringIteratorPrototype% Object

    5.1%RegExpStringIteratorPrototype%.next ( )

    -
    1. Let O be the this value.
    2. If Type(O) is not Object, throw a TypeError exception.
    3. If O does not have all of the internal slots of a RegExp String Iterator Object Instance (see 5.3), throw a TypeError exception.
    4. If O.[[Done]] is true, then
      1. Return ! CreateIterResultObject(null, true).
    5. Let R be O.[[IteratingRegExp]].
    6. Let S be O.[[IteratedString]].
    7. Let global be O.[[Global]].
    8. Let fullUnicode be O.[[Unicode]].
    9. Let match be ? RegExpExec(R, S).
    10. If match is null, then
      1. Set O.[[Done]] to true.
      2. Return ! CreateIterResultObject(null, true).
    11. Else,
      1. If global is true,
        1. Let matchStr be ? ToString(? Get(match, "0")).
        2. If matchStr is the empty string,
          1. Let thisIndex be ? ToLength(? Get(R, "lastIndex")).
          2. Let nextIndex be ! AdvanceStringIndex(S, thisIndex, fullUnicode).
          3. Perform ? Set(R, "lastIndex", nextIndex, true).
        3. Return ! CreateIterResultObject(match, false).
      2. Else,
        1. Let previousIndex be O.[[PreviousIndex]].
        2. Assert: Type(previousIndex) is Number.
        3. Let index be ? ToLength(? Get(match, "index")).
        4. If previousIndex is equal to index, then
          1. Set O.[[Done]] to true.
          2. Return ! CreateIterResultObject(null, true).
        5. Else,
          1. Set O.[[PreviousIndex]] to index.
          2. Return ! CreateIterResultObject(match, false). -
    +
    1. Let O be the this value.
    2. If Type(O) is not Object, throw a TypeError exception.
    3. If O does not have all of the internal slots of a RegExp String Iterator Object Instance (see 5.3), throw a TypeError exception.
    4. If O.[[Done]] is true, then
      1. Return ! CreateIterResultObject(null, true).
    5. Let R be O.[[IteratingRegExp]].
    6. Let S be O.[[IteratedString]].
    7. Let global be O.[[Global]].
    8. Let fullUnicode be O.[[Unicode]].
    9. Let match be ? RegExpExec(R, S).
    10. If match is null, then
      1. Set O.[[Done]] to true.
      2. Return ! CreateIterResultObject(null, true).
    11. Else,
      1. If global is true,
        1. Let matchStr be ? ToString(? Get(match, "0")).
        2. If matchStr is the empty string,
          1. Let thisIndex be ? ToLength(? Get(R, "lastIndex")).
          2. Let nextIndex be ! AdvanceStringIndex(S, thisIndex, fullUnicode).
          3. Perform ? Set(R, "lastIndex", nextIndex, true).
        3. Return ! CreateIterResultObject(match, false).
      2. Else,
        1. Set O.[[Done]] to true.
        2. Return ! CreateIterResultObject(match, false). +
    @@ -2286,7 +2286,7 @@

    5.3Properties of RegExp String Iterator Instance [[IteratingRegExp]] - The regular expression used for iteration. IsRegExp([[IteratingRegExp]]) is always initially true. + The regular expression used for iteration. IsRegExp([[IteratingRegExp]]) is always initially true. [[IteratedString]] @@ -2300,10 +2300,6 @@

    5.3Properties of RegExp String Iterator Instance [[Unicode]] A Boolean value to indicate whether the [[IteratingRegExp]] is in full Unicode mode or not. - - [[PreviousIndex]] - The index of the previous yielded match object, for non-global regular expressions. - [[Done]] A Boolean value to indicate whether the iteration is complete or not. diff --git a/spec.emu b/spec.emu index 8db7841..f5d805e 100644 --- a/spec.emu +++ b/spec.emu @@ -72,12 +72,11 @@ contributors: Jordan Harband 1. Assert: Type(_S_) is String. 1. Assert: Type(_global_) is Boolean. 1. Assert: Type(_fullUnicode_) is Boolean. - 1. Let _iterator_ be ObjectCreate(%RegExpStringIteratorPrototype%, « [[IteratingRegExp]], [[IteratedString]], [[PreviousIndex]], [[Done]] »). + 1. Let _iterator_ be ObjectCreate(%RegExpStringIteratorPrototype%, « [[IteratingRegExp]], [[IteratedString]], [[Done]] »). 1. Set _iterator_.[[IteratingRegExp]] to _R_. 1. Set _iterator_.[[IteratedString]] to _S_. 1. Set _iterator_.[[Global]] to _global_. 1. Set _iterator_.[[Unicode]] to _fullUnicode_. - 1. Set _iterator_.[[PreviousIndex]] to *-1*. 1. Set _iterator_.[[Done]] to *false*. 1. Return _iterator_. @@ -115,15 +114,8 @@ contributors: Jordan Harband 1. Perform ? Set(_R_, *"lastIndex"*, _nextIndex_, *true*). 1. Return ! CreateIterResultObject(_match_, *false*). 1. Else, - 1. Let _previousIndex_ be _O_.[[PreviousIndex]]. - 1. Assert: Type(_previousIndex_) is Number. - 1. Let _index_ be ? ToLength(? Get(_match_, *"index"*)). - 1. If _previousIndex_ is equal to _index_, then - 1. Set _O_.[[Done]] to *true*. - 1. Return ! CreateIterResultObject(*null*, *true*). - 1. Else, - 1. Set _O_.[[PreviousIndex]] to _index_. - 1. Return ! CreateIterResultObject(_match_, *false*). + 1. Set _O_.[[Done]] to *true*. + 1. Return ! CreateIterResultObject(_match_, *false*). @@ -158,11 +150,7 @@ contributors: Jordan Harband [[Unicode]] - A Boolean value to indicate whether the [[IteratingRegExp]] is in full Unicode mode or not. - - - [[PreviousIndex]] - The index of the previous yielded match object, for non-global regular expressions. + A Boolean value to indicate whether the [[IteratingRegExp]] is in Unicode mode or not. [[Done]] diff --git a/spec.md b/spec.md index 67a533a..d68fb1e 100644 --- a/spec.md +++ b/spec.md @@ -44,12 +44,11 @@ The abstract operation *CreateRegExpStringIterator* is used to create such itera 1. Assert: [Type][type](*S*) is String. 1. Assert: [Type][type](*global*) is Boolean. 1. Assert: [Type][type](*unicode*) is Boolean. - 1. Let *iterator* be ObjectCreate(%RegExpStringIteratorPrototype%, « [[IteratedString]], [[IteratingRegExp]], [[PreviousIndex]], [[Done]] »). + 1. Let *iterator* be ObjectCreate(%RegExpStringIteratorPrototype%, « [[IteratedString]], [[IteratingRegExp]], [[Done]] »). 1. Set *iterator*.[[IteratingRegExp]] to *R*. 1. Set *iterator*.[[IteratedString]] to *S*. 1. Set *iterator*.[[Global]] to *global*. 1. Set *iterator*.[[Unicode]] to *fullUnicode*. - 1. Set *iterator*.[[PreviousIndex]] to **-1**. 1. Set *iterator*.[[Done]] to **true**. 1. Return *iterator*. @@ -80,15 +79,8 @@ All RegExp String Iterator Objects inherit properties from the [%RegExpStringIte 1. Perform ? [Set][set](*R*, **"lastIndex"**, *nextIndex*, **true**). 1. Return ! [CreateIterResultObject][create-iter-result-object](*match*, **false**). 1. Else, - 1. Let *previousIndex* be *O*.[[PreviousIndex]]. - 1. Assert: Type(*previousIndex*) is Number. - 1. Let *index* be ? [ToLength][tolength](? [Get][get](*match*, **"index"**). - 1. If *previousIndex* is equal to *index*, then - 1. Set *O*.[[Done]] to **true**. - 1. Return ! [CreateIterResultObject][create-iter-result-object](**null**, **true**). - 1. Else, - 1. Set *O*.[[PreviousIndex]] to *index*. - 1. Return ! [CreateIterResultObject][create-iter-result-object](_match_, **false**). + 1. Set *O*.[[Done]] to **true**. + 1. Return ! [CreateIterResultObject][create-iter-result-object](_match_, **false**). #### %RegExpStringIteratorPrototype%[ @@toStringTag ] @@ -121,11 +113,7 @@ RegExp String Iterator instances are ordinary objects that inherit properties fr [[Unicode]] - A Boolean value to indicate whether the [[IteratingRegExp]] is in full Unicode more or not. - - - [[PreviousIndex]] - The index of the previous yielded match object. + A Boolean value to indicate whether the [[IteratingRegExp]] is in Unicode mode or not. [[Done]]