tor-browser

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

string-replace-get.js (1085B)


      1 // Copyright 2017 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 description: Named substitutions are found by getting the property from the groups object
      6 esid: sec-getsubstitution
      7 features: [regexp-named-groups]
      8 info: |
      9  Runtime Semantics: GetSubstitution( matched, str, position, captures, namedCaptures, replacement )
     10 
     11  Table: Replacement Text Symbol Substitutions
     12 
     13  Unicode Characters: $<
     14  Replacement text:
     15    2. Otherwise,
     16      c. Let capture be ? Get(namedCaptures, groupName).
     17      d. If capture is undefined, replace the text through > with the empty string.
     18      e. Otherwise, replace the text through this following > with ? ToString(capture).
     19 ---*/
     20 
     21 let source = "(?<fst>.)(?<snd>.)|(?<thd>x)";
     22 for (let flags of ["g", "gu"]) {
     23  let re = new RegExp(source, flags);
     24  assert.sameValue("badc", "abcd".replace(re, "$<snd>$<fst>"));
     25 }
     26 for (let flags of ["", "u"]) {
     27  let re = new RegExp(source, flags);
     28  assert.sameValue("bacd", "abcd".replace(re, "$<snd>$<fst>"));
     29 }
     30 
     31 reportCompare(0, 0);