Skip to content

regex: honor custom exec methods in RegExp.prototype.test - #2269

Open
leventov wants to merge 1 commit into
meta:static_hfrom
convex-in-prod:upstream-regexp-test-dispatch
Open

leventov wants to merge 1 commit into
meta:static_hfrom
convex-in-prod:upstream-regexp-test-dispatch

Conversation

@leventov

Copy link
Copy Markdown

Summary

RegExp.prototype.test currently invokes the builtin matcher directly. That ignores an overridden exec and rejects generic object receivers whose callable exec returns an object or null.

Use the existing RegExpExec implementation after checking the receiver and coercing the argument to a string. This preserves the specified ordering when string coercion changes exec, invokes an exec getter once, validates custom results, and retains builtin fallback for a real RegExp with a noncallable exec.

The now single-use builtin exec helper is inlined into regExpPrototypeExec. This PR contains the dispatch correction only; result-allocation optimizations are separate.

Test Plan

The new regression covers custom methods, generic receivers, invalid primitive results, non-object receivers, noncallable fallback, coercion/getter/call ordering, mutation during coercion, propagated exceptions and a getter returning the builtin method.

Built Hermes from this branch. The regression passed in normal execution, -O, and emitted-bytecode execution. The same assertions also passed in Node as a reference implementation.

RegExp.prototype.test must use RegExpExec after coercing its argument to
a string. Calling the builtin implementation directly bypasses overridden
exec methods and rejects otherwise valid generic object receivers.

Use the existing RegExpExec implementation, including its object-or-null
return check. Inline the now single-use exec helper into its entrypoint.
Cover dispatch, coercion order, getter effects, invalid returns, exceptions
and noncallable exec fallback on real RegExp objects.
@meta-cla meta-cla Bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Oct 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant