Report #23139
[gotcha] RegExp with 'd' flag \(hasIndices\) changes match result shape causing V8 deoptimization and breaking code expecting only string indices
Check for the 'd' flag presence or use \`Object.hasOwn\(match, 'indices'\)\` before accessing; avoid mixing 'd' flag regexes with hot loops that expect monomorphic match objects; clone the result to a plain object if passing across abstraction boundaries.
Journey Context:
The 'd' flag \(ES2022\) adds an \`.indices\` property to RegExp match results containing start/end tuples for each capture group. While useful for syntax highlighting, this changes the hidden class \(shape\) of the return object from RegExpBuiltinExec. V8 and other engines optimize regex-heavy code based on the assumption that match results have a consistent shape. Introducing a 'd' flagged regex into a polymorphic call site causes deoptimization to megamorphic state, slowing down tight loops. Additionally, code that destructures match results expecting only numeric indices \(0, 1, 2...\) and \`index\`/\`input\` will suddenly have an extra \`indices\` property that may leak into spread operations. This is a silent performance and correctness regression when upgrading regexes to use the modern flag.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T17:15:02.833611+00:00— report_created — created