Motivation
Surfaced during the #69 RegExp folder rollout (commit b968a9e). Built-in prototype methods (RegExp.prototype.exec, RegExp.prototype.test, etc.) are missing two spec-required behaviors:
.length is not exposed. RegExp.prototype.exec.length === 1 should be true. We return undefined (or throw).
- Receiver-type checks missing.
RegExp.prototype.exec.call({}, "...") should TypeError because {} isn't a RegExp. We silently proceed and return wrong values.
Both stem from the same architectural shape: BuiltInMethod / TSFunction instances representing prototype methods don't expose the Function.prototype properties (name, length) the spec mandates, and don't validate this against the expected internal slot.
Sample failing tests
test/built-ins/RegExp/prototype/exec/S15.10.6.2_A11.js:
assert.sameValue(RegExp.prototype.exec.hasOwnProperty("length"), true);
assert.sameValue(RegExp.prototype.exec.length, 1); // RuntimeError: undefined
test/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T1.js:
var __instance = new Object;
__instance.exec = RegExp.prototype.exec;
__instance.exec("..."); // should TypeError; we return null/garbage
Impact
| Cluster |
Count |
RegExp.prototype.exec length / receiver |
21 (interp) + 21 (compile) |
RegExp.prototype.test length / receiver |
18 (interp) + 16 (compile) |
(Same pattern likely affects String.prototype.*, Array.prototype.*, etc., across the whole baseline) |
unknown but large |
The 65-test count above is just RegExp; the length issue is cross-cutting — every built-in method instance in SharpTS is affected.
Suggested approach
- Wire
.length on built-in methods. BuiltInMethod (Runtime/BuiltIns/BuiltInMethod.cs) and TSFunction (compile mode) should expose .length reflecting the formal parameter count of the underlying delegate. Same place that exposes .name should expose .length.
- Add receiver-type checks to RegExp prototype methods. Each method validates
this has the [[RegExpMatcher]] internal slot before proceeding; throw TypeError otherwise. The interpreter's Runtime/Types/SharpTSRegExp.cs and compile-mode's RuntimeEmitter.RegExp.cs (or wherever the dispatch lives) need this guard.
- Generalize the receiver check to a cross-cutting helper so the same pattern can be applied to
Array.prototype.*, Map.prototype.*, etc. as those gaps surface.
Acceptance
RegExp.prototype.exec.length === 1 and the same for test.
RegExp.prototype.exec.call({}, "...") throws TypeError.
- The ~65 RegExp tests above flip out of
RuntimeError/Fail.
- Sanity-check:
String.prototype.charAt.length, Array.prototype.push.length, Function.prototype.call.length all return correct values (these may already work — verify).
Related
Part of #69. Likely a foundational fix that unblocks more of #103 and beyond.
Motivation
Surfaced during the #69 RegExp folder rollout (commit b968a9e). Built-in prototype methods (
RegExp.prototype.exec,RegExp.prototype.test, etc.) are missing two spec-required behaviors:.lengthis not exposed.RegExp.prototype.exec.length === 1should betrue. We returnundefined(or throw).RegExp.prototype.exec.call({}, "...")shouldTypeErrorbecause{}isn't a RegExp. We silently proceed and return wrong values.Both stem from the same architectural shape:
BuiltInMethod/TSFunctioninstances representing prototype methods don't expose theFunction.prototypeproperties (name,length) the spec mandates, and don't validatethisagainst the expected internal slot.Sample failing tests
test/built-ins/RegExp/prototype/exec/S15.10.6.2_A11.js:test/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T1.js:Impact
RegExp.prototype.execlength / receiverRegExp.prototype.testlength / receiverString.prototype.*,Array.prototype.*, etc., across the whole baseline)The 65-test count above is just RegExp; the
lengthissue is cross-cutting — every built-in method instance in SharpTS is affected.Suggested approach
.lengthon built-in methods.BuiltInMethod(Runtime/BuiltIns/BuiltInMethod.cs) andTSFunction(compile mode) should expose.lengthreflecting the formal parameter count of the underlying delegate. Same place that exposes.nameshould expose.length.thishas the[[RegExpMatcher]]internal slot before proceeding; throwTypeErrorotherwise. The interpreter'sRuntime/Types/SharpTSRegExp.csand compile-mode'sRuntimeEmitter.RegExp.cs(or wherever the dispatch lives) need this guard.Array.prototype.*,Map.prototype.*, etc. as those gaps surface.Acceptance
RegExp.prototype.exec.length === 1and the same fortest.RegExp.prototype.exec.call({}, "...")throwsTypeError.RuntimeError/Fail.String.prototype.charAt.length,Array.prototype.push.length,Function.prototype.call.lengthall return correct values (these may already work — verify).Related
Part of #69. Likely a foundational fix that unblocks more of #103 and beyond.