Commit 5d5a6595 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[regexp] Fix invalid DCHECK in named capture logic

The `capture_ix` refers to all captures while `capture_count` only
refers to named captures. Clarified by renaming `capture_count` to
`named_capture_count` and removing the incorrect part of the DCHECK.

The `>= 1` part of the condition must still hold since named captures
can only refer to explicit capture groups, which start at index 1.

Tbr: petermarshall@chromium.org
Bug: chromium:1018592
Change-Id: If8a26f6661ba0483d585f74270b3b4a3853e2ca8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1886810Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64629}
parent 3358bb04
......@@ -1055,15 +1055,15 @@ Handle<JSObject> ConstructNamedCaptureGroupsObject(
const std::function<Object(int)>& f_get_capture) {
Handle<JSObject> groups = isolate->factory()->NewJSObjectWithNullProto();
const int capture_count = capture_map->length() >> 1;
for (int i = 0; i < capture_count; i++) {
const int named_capture_count = capture_map->length() >> 1;
for (int i = 0; i < named_capture_count; i++) {
const int name_ix = i * 2;
const int index_ix = i * 2 + 1;
Handle<String> capture_name(String::cast(capture_map->get(name_ix)),
isolate);
const int capture_ix = Smi::ToInt(capture_map->get(index_ix));
DCHECK(1 <= capture_ix && capture_ix <= capture_count);
DCHECK_GE(capture_ix, 1); // Explicit groups start at index 1.
Handle<Object> capture_value(f_get_capture(capture_ix), isolate);
DCHECK(capture_value->IsUndefined(isolate) || capture_value->IsString());
......
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const re = /()()()()(?<aaaab>)1/;
"111a1a".replace(re, () => {}) ;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment