Repository navigation
Conversation
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.
Separate builtin matching and observable state updates from JavaScript match-result construction. Boolean tests retain capture ranges and legacy match state without building result arrays, substrings, groups or indices. Guard the builtin path against overridden exec methods and effectful property access. For global empty-string replacement, append unmatched spans directly after the required coercions, flag reads and lastIndex write. Retain zero-width Unicode advancement and ordinary error behavior. Compare the optimized operations with a custom exec forwarding to the builtin, covering captures, legacy state, flags, getters and write errors.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Builtin Boolean regex tests currently construct a full JavaScript match result and immediately discard it. Global replacement with an empty string also constructs match arrays and intermediate match strings that are not observable when dispatch stays on the builtin path.
Separate matching and observable state updates from JavaScript result construction. Boolean consumers retain native capture ranges, legacy match state and
lastIndexupdates without building the match array, capture substrings, groups object or indices object. Eligible empty global replacements append unmatched spans directly.Custom dispatch still follows
RegExpExec. The no-lookup shortcut requires an ordinary data property resolving to the actual builtinexec; accessors and proxy/host prototype chains retain normal property access. Replacement takes the shortcut only after input/replacement coercion, global/unicode property reads and the initiallastIndexwrite, with both observable and internal global flags enabled.This builds on #2269; the first commit is that correctness fix and the second is the allocation change. Generated matchers, shared literal bytecode, compiler fusion and changes to the general regex matching algorithm are outside this PR. Failed matches have fewer allocations to remove, so the benefit depends on the workload.
Test Plan
Built Hermes and Static Hermes from the extracted branch. Both the new regression and the dispatch regression pass in normal Hermes execution,
-O, emitted-bytecode execution, andshermes -exec -O. The new differential assertions also pass in Node.Regressions compare builtin operations with an overridden
execforwarding to the original method, including captures, named groups/indices, legacy state, global/sticky behavior, zero-width Unicode advancement, failed matches, getter/coercion order and nonwritablelastIndexerrors.