tor-browser

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

groups-object-subclass.js (1123B)


      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: >
      6  Test the groups object on RegExp subclass results that have their own.
      7 esid: sec-regexpbuiltinexec
      8 features: [regexp-named-groups]
      9 info: |
     10  Runtime Semantics: RegExpBuiltinExec ( R, S )
     11    24. If _R_ contains any |GroupName|, then
     12      a. Let _groups_ be ObjectCreate(*null*).
     13    25. Else,
     14      a. Let _groups_ be *undefined*.
     15    26. Perform ! CreateDataProperty(_A_, `"groups"`, _groups_).
     16 ---*/
     17 
     18 class FakeRegExp extends RegExp {
     19  exec(subject) {
     20    const fakeResult = ["ab", "a"];
     21    fakeResult.index = 0;
     22    fakeResult.groups = { a: "b" };
     23    Object.getPrototypeOf(fakeResult.groups).b = "c";
     24    return fakeResult;
     25  }
     26 };
     27 
     28 const re = new FakeRegExp();
     29 const result = re.exec("ab");
     30 assert.sameValue(Object.getPrototypeOf(result), Array.prototype);
     31 assert(result.hasOwnProperty("groups"));
     32 assert.sameValue("b", result.groups.a);
     33 assert.sameValue("b", "ab".replace(re, "$<a>"));
     34 assert.sameValue("c", "ab".replace(re, "$<b>"));
     35 
     36 reportCompare(0, 0);