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
- 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)
- Each must dispatch through
RegExpExec so lastIndex coercion works (current named methods may already do this — wire the symbols to the same code path).
- 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.
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 onRegExp.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:test/built-ins/RegExp/prototype/Symbol.replace/arg-1-coerce.js:Impact
Total: ~290 tests across both modes.
Suggested approach
RegExp.prototypeper 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)RegExpExecsolastIndexcoercion works (current named methods may already do this — wire the symbols to the same code path).obj[Symbol.X](...)properly resolves the symbol-keyed slot rather than falling through to a string-keyed lookup.Acceptance
RuntimeError/FailtoPassor 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).String/prototype/*orRegExp/prototype/*baselines.Related
Part of #69. Sibling cluster issues filed concurrently.