Skip to content

Test262 #2: RegExp prototype is missing Symbol.match/replace/split/search/matchAll dispatch (~290 tests) #101

@nickna

Description

@nickna

Motivation

Surfaced during the #69 RegExp folder rollout (commit b968a9e). Test262's RegExp/prototype/Symbol.{match, replace, split, search, matchAll}/* directories test the well-known-symbol-keyed protocol methods that ECMA-262 §22.2.5 mandates on RegExp.prototype.

In SharpTS, r[Symbol.match](...), r[Symbol.replace](...), etc. either runtime-error (interpreter) or produce wrong values (compiler). The named-method API (r.exec(...), 'foo'.replace(/./, ...)) works; the symbol-keyed protocol does not.

Sample failing tests

  • test/built-ins/RegExp/prototype/Symbol.match/builtin-coerce-lastindex.js:
    var r = /./y;
    r.lastIndex = '1.9';
    result = r[Symbol.match]('abc');   // RuntimeError: Symbol.match not on RegExp prototype
  • test/built-ins/RegExp/prototype/Symbol.replace/arg-1-coerce.js:
    /./[Symbol.replace](arg, 'x');     // RuntimeError

Impact

Bucket Symbol.match Symbol.replace Symbol.split Symbol.matchAll Symbol.search Total
Interp RuntimeError 39 39 29 15 11 133
Compile Fail 35 52 35 15 18 155

Total: ~290 tests across both modes.

Suggested approach

  1. Implement the four Symbol-keyed methods on RegExp.prototype per ECMA-262:
    • RegExp.prototype[Symbol.match] (§22.2.5.7)
    • RegExp.prototype[Symbol.replace] (§22.2.5.10)
    • RegExp.prototype[Symbol.search] (§22.2.5.11)
    • RegExp.prototype[Symbol.split] (§22.2.5.13)
    • RegExp.prototype[Symbol.matchAll] (§22.2.5.8)
  2. Each must dispatch through RegExpExec so lastIndex coercion works (current named methods may already do this — wire the symbols to the same code path).
  3. Compile mode emits the same dispatch — verify the IL path for obj[Symbol.X](...) properly resolves the symbol-keyed slot rather than falling through to a string-keyed lookup.

Acceptance

  • All 290 tests above flip out of RuntimeError/Fail to Pass or to a more specific bucket.
  • String.prototype.{match, replace, search, split, matchAll} continue to delegate through the symbol protocol on a regex argument (existing behavior preserved).
  • No regressions in String/prototype/* or RegExp/prototype/* baselines.

Related

Part of #69. Sibling cluster issues filed concurrently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions