From 2d8696c4fea958d199b3b92f29d685ec5be7ed45 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sat, 9 Nov 2024 19:17:11 +0100 Subject: [PATCH] Issue #2305 Part 3a: Pass ResultTemplateKind through CreateRegExpMatchResult This sets up the MatchResult with the proper structure to contain indices when necessary. --- js/src/builtin/RegExp.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/js/src/builtin/RegExp.cpp b/js/src/builtin/RegExp.cpp index 198610438c..590010b868 100644 --- a/js/src/builtin/RegExp.cpp +++ b/js/src/builtin/RegExp.cpp @@ -32,7 +32,7 @@ using mozilla::Maybe; using CapturesVector = GCVector; /* - * ES 2021 draft 21.2.5.2.2: Steps 16-28 + * Implements RegExpBuiltinExec: Steps 18-35 * https://tc39.es/ecma262/#sec-regexpbuiltinexec */ bool @@ -51,10 +51,16 @@ js::CreateRegExpMatchResult(JSContext* cx, RegExpShared& re, * input: input string * index: start index for the match * groups: named capture groups for the match + * indices: capture indices for the match, if required */ + bool hasIndices = re.hasIndices(); + /* Get the templateObject that defines the shape and type of the output object */ - JSObject* templateObject = cx->compartment()->regExps.getOrCreateMatchResultTemplateObject(cx); + RegExpCompartment::ResultTemplateKind kind = + hasIndices ? RegExpCompartment::ResultTemplateKind::WithIndices + : RegExpCompartment::ResultTemplateKind::Normal; + JSObject* templateObject = cx->compartment()->regExps.getOrCreateMatchResultTemplateObject(cx, kind); if (!templateObject) return false;