feat(runtime): implement regex d flag (hasIndices) - #4930
Merged
proggeramlug merged 2 commits intoJun 10, 2026
Merged
Conversation
Add support for the ES2022 RegExp `d` flag which attaches an `indices` property to match results containing start/end character positions for each capture group. Implementation: - Add set_exec_array_indices() for standard regex::Regex matches - Add set_exec_array_indices_fancy() for fancy_regex matches - Convert byte offsets to character indices - Handle unmatched groups as undefined - Support named capture groups via .groups property Tests: - test-files/test_regex_d_flag.ts: 18 comprehensive test cases - tests/test_regex_d_flag.sh: basic shell test - tests/test_regex_d_flag_comprehensive.sh: 5 shell test scenarios
Non-global String.prototype.match delegates to RegExpExec, so its result must carry the same `indices` array as RegExp.prototype.exec under the `d` flag. js_string_match built its own result array and never called set_exec_array_indices, so `str.match(/re/d).indices` was undefined. Wire set_exec_array_indices (standard) and set_exec_array_indices_fancy (lookbehind/backref fallback) into both non-global branches of js_string_match. Also correct the test file's hand-written expected-output comments for tests 4/11/14 to match Node (exec output was already correct; the comments were wrong).
Contributor
|
Thanks @nglmercer great addition! |
proggeramlug
pushed a commit
that referenced
this pull request
Jun 10, 2026
proggeramlug
pushed a commit
that referenced
this pull request
Jun 10, 2026
…ine CI cap #4930 (regex d flag) pushed regex.rs to 2260 lines, tripping the lint job's file-size gate on every PR merged after it. Extract the match- result array decoration group (index/input/groups/indices builders for both the regex-crate fast path and the fancy_regex fallback, plus the char/byte index converters) into regex/exec_array.rs — same recipe as the date.rs split (#4925). No behavior change; d-flag output verified byte-identical with Node post-split.
proggeramlug
added a commit
that referenced
this pull request
Jun 10, 2026
…nstructable via new (#4904) (#4936) * fix(http): make Agent/ClientRequest/IncomingMessage/ServerResponse constructable via new (#4904) Node exposes http.Agent, http.ClientRequest, http.IncomingMessage, and http.ServerResponse as constructable classes; under Perry, new-ing them threw 'TypeError: <X> is not a constructor' through every value-aliasing path (const { Agent } = require('http'), require('_http_agent').Agent, const CR = http.ClientRequest, new http.IncomingMessage(), ...). Mechanism (mirrors the existing OutgoingMessage route end-to-end): - runtime/native_module: export the four classes (plus the previously missing http.get / http.request twins of the https entries) as bound callable values with Node .length arities. - runtime/class_registry: extend the http construct arm so js_new_function_construct forwards (module, class, args) through JS_NATIVE_HTTP_DISPATCH; forward the real module name so https.Agent constructs with the https protocol default. - stdlib/dispatch: constructor arms — Agent -> js_http_agent_new, ClientRequest -> new js_http_client_request_standalone_new, IncomingMessage/ServerResponse -> new standalone factories in perry-ext-http-server; plus get/request value-call arms. - HIR: member-form new http.{ClientRequest,IncomingMessage, ServerResponse}() joins the OutgoingMessage NewDynamic route; bare-ident forms (destructured imports) added for all four classes; the three handle-backed classes are skip-listed from typed native-instance registration so instances dispatch dynamically. - cjs_wrap: require('_http_agent') (and the other _http_* internal modules) binds its hoisted import to the public 'http' surface. Instance surface (perry-ext-http-server): - IncomingMessage: standalone constructor storing the socket argument; socket/connection get/set aliasing (Node's connection accessor writes this.socket); _addHeaderLine with Node's matchKnownFields semantics (first-wins singles, ', '/'; ' joins, set-cookie array). - ServerResponse: standalone constructor (req.method captured; HEAD suppresses the body), assignSocket/detachSocket with ERR_HTTP_SOCKET_ASSIGNED on double assignment, write(chunk, cb) callback queueing, end() flushing head+body through the assigned socket's JS write method (one corked write + the zero-length finish chunk), write/end callbacks invoked in order. - Agent: dynamic property reads (maxSockets, freeSockets, protocol, ...) and writes (tunables + createConnection/createSocket monkeypatching) through handle dispatch in both perry-stdlib and perry-ext-http. Also fixes a latent SIGSEGV: json/stringify's is_closure_value probed CLOSURE_MAGIC at offset 12 of POINTER_TAG payloads without the handle- band guard (same #2154 bug class as the sibling probe in the file), so JSON.stringify of { agent, lookup: () => {} } dereferenced unmapped low memory. Route through addr_class::is_handle_band first. Node corpus (test/parallel, pinned v22): 7 of the 13 tests in #4904 now pass outright (client-defaults, agent-timeout-option, client-timeout-option-with-agent, incoming-message-connection-setter, incoming-message-destroy, outgoing-message-write-callback, server-response-standalone); the other 6 construct and run to their assertions, failing on deeper Agent pool emulation (sockets/freeSockets per-key arrays, real createConnection sockets) and a pre-existing deepStrictEqual divergence, tracked separately. Closes #4904. Part of #2132. * chore: cargo fmt — regex.rs long call from #4930 landed unformatted * chore(runtime): split regex.rs exec-array decoration under the 2000-line CI cap #4930 (regex d flag) pushed regex.rs to 2260 lines, tripping the lint job's file-size gate on every PR merged after it. Extract the match- result array decoration group (index/input/groups/indices builders for both the regex-crate fast path and the fancy_regex fallback, plus the char/byte index converters) into regex/exec_array.rs — same recipe as the date.rs split (#4925). No behavior change; d-flag output verified byte-identical with Node post-split. --------- Co-authored-by: Ralph Küpper <ralph@skelpo.com>
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
Adds support for the ES2022 RegExp
dflag (hasIndices), which attaches anindicesproperty to match results containing start/end character positions for each capture group.Changes
crates/perry-runtime/src/regex.rs(+260 lines)set_exec_array_indices()— attachesindicesto match-result arrays for standardregex::Regexmatchesset_exec_array_indices_fancy()— same forfancy_regex::Regexcaptures (lookbehind/backreference patterns).indexbehavior)undefined.groupsproperty on the indices arrayTests
test-files/test_regex_d_flag.ts— 18 comprehensive test cases covering basic indices, capture groups, named groups, unmatched groups,hasIndicesgetter,match(), global match, empty matches, zero-width assertions, lookbehind, backreferences, complex URL pattern, own property check, aliasing, andRegExpconstructortests/test_regex_d_flag.sh— basic shell regression testtests/test_regex_d_flag_comprehensive.sh— 5 shell test scenariosTest Results
All 18 TypeScript test cases pass. Both shell test suites pass.