tor-browser

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

string-replace-undefined.js (971B)


      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: If a named group was not reached, it is replaced by the empty string
      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 ---*/
     19 
     20 let source = "(?<fst>.)(?<snd>.)|(?<thd>x)";
     21 for (let flags of ["g", "gu"]) {
     22  let re = new RegExp(source, flags);
     23  assert.sameValue("", "abcd".replace(re, "$<thd>"));
     24 }
     25 for (let flags of ["", "u"]) {
     26  let re = new RegExp(source, flags);
     27  assert.sameValue("cd", "abcd".replace(re, "$<thd>"));
     28 }
     29 
     30 reportCompare(0, 0);