v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
regexp-match-info.cc
Go to the documentation of this file.
1// Copyright 2023 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <optional>
6
8
9namespace v8::internal {
10
11// static
13 int capture_count,
14 AllocationType allocation) {
15 int capacity = JSRegExp::RegistersForCaptureCount(capture_count);
16 DCHECK_GE(capacity, kMinCapacity);
17 std::optional<DisallowGarbageCollection> no_gc;
19 Allocate(isolate, capacity, &no_gc, allocation);
20
21 ReadOnlyRoots roots{isolate};
22 MemsetTagged(result->RawFieldOfFirstElement(), Smi::zero(), capacity);
23 result->set_number_of_capture_registers(capacity);
24 result->set_last_subject(*isolate->factory()->empty_string(),
26 result->set_last_input(roots.undefined_value(), SKIP_WRITE_BARRIER);
27
28 return result;
29}
30
32 Isolate* isolate, DirectHandle<RegExpMatchInfo> match_info,
33 int capture_count) {
34 int required_capacity = JSRegExp::RegistersForCaptureCount(capture_count);
35 if (required_capacity > match_info->capacity()) {
36 DirectHandle<RegExpMatchInfo> new_info = New(isolate, capture_count);
37 RegExpMatchInfo::CopyElements(isolate, *new_info, 0, *match_info, 0,
38 match_info->capacity());
39 match_info = new_info;
40 }
41 match_info->set_number_of_capture_registers(required_capacity);
42 return match_info;
43}
44
45} // namespace v8::internal
static constexpr int RegistersForCaptureCount(int count)
Definition js-regexp.h:90
static DirectHandle< RegExpMatchInfo > ReserveCaptures(Isolate *isolate, DirectHandle< RegExpMatchInfo > match_info, int capture_count)
static constexpr int kMinCapacity
static V8_EXPORT_PRIVATE DirectHandle< RegExpMatchInfo > New(Isolate *isolate, int capture_count, AllocationType allocation=AllocationType::kYoung)
static constexpr Tagged< Smi > zero()
Definition smi.h:99
static Handle< RegExpMatchInfo > Allocate(IsolateT *isolate, int capacity, std::optional< DisallowGarbageCollection > *no_gc_out, AllocationType allocation=AllocationType::kYoung)
static void CopyElements(Isolate *isolate, Tagged< RegExpMatchInfo > dst, int dst_index, Tagged< RegExpMatchInfo > src, int src_index, int len, WriteBarrierMode mode=kDefaultMode)
ZoneVector< RpoNumber > & result
@ SKIP_WRITE_BARRIER
Definition objects.h:52
void MemsetTagged(Tagged_t *start, Tagged< MaybeObject > value, size_t counter)
Definition slots-inl.h:486
#define DCHECK_GE(v1, v2)
Definition logging.h:488