tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

indices-array-unmatched.js (1155B)


      1 // Copyright 2019 Ron Buckton. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 description: An unmatched capture in a match corresponds to an unmatched capture in "indices"
      6 esid: sec-makeindicesarray
      7 features: [regexp-match-indices]
      8 info: |
      9  MakeIndicesArray ( S, indices, groupNames )
     10    4. Let _n_ be the number of elements in _indices_.
     11    ...
     12    6. Set _A_ to ! ArrayCreate(_n_).
     13    ...
     14    11. For each integer _i_ such that _i_ >= 0 and _i_ < _n_, do
     15      a. Let _matchIndices_ be _indices_[_i_].
     16      b. If _matchIndices_ is not *undefined*, then
     17        i. Let _matchIndicesArray_ be ! GetMatchIndicesArray(_S_, _matchIndices_).
     18      c. Else,
     19        i. Let _matchIndicesArray_ be *undefined*.
     20      d. Perform ! CreateDataProperty(_A_, ! ToString(_n_), _matchIndicesArray_).
     21        ...
     22 ---*/
     23 
     24 let input = "abd";
     25 let match = /b(c)?/d.exec(input);
     26 let indices = match.indices;
     27 
     28 // `indices` has the same length as match
     29 assert.sameValue(indices.length, match.length);
     30 
     31 // The second element of `indices` should be undefined.
     32 assert.sameValue(indices[1], undefined);
     33 
     34 reportCompare(0, 0);