#include <functional>
#include "src/base/small-vector.h"
#include "src/base/strings.h"
#include "src/common/message-template.h"
#include "src/execution/arguments-inl.h"
#include "src/execution/isolate-inl.h"
#include "src/heap/heap-inl.h"
#include "src/logging/counters.h"
#include "src/numbers/conversions-inl.h"
#include "src/objects/js-array-inl.h"
#include "src/objects/js-regexp-inl.h"
#include "src/regexp/regexp-utils.h"
#include "src/regexp/regexp.h"
#include "src/strings/string-builder-inl.h"
#include "src/strings/string-search.h"
namespace v8 {
namespace internal {
namespace {
constexpr int kStaticVectorSlots = …;
uint32_t GetArgcForReplaceCallable(uint32_t num_captures,
bool has_named_captures) { … }
int LookupNamedCapture(const std::function<bool(Tagged<String>)>& name_matches,
Tagged<FixedArray> capture_name_map, int* index_in_out) { … }
}
class CompiledReplacement { … };
bool CompiledReplacement::Compile(Isolate* isolate,
DirectHandle<JSRegExp> regexp,
DirectHandle<RegExpData> regexp_data,
Handle<String> replacement, int capture_count,
int subject_length) { … }
void CompiledReplacement::Apply(ReplacementStringBuilder* builder,
int match_from, int match_to, int32_t* match) { … }
void FindOneByteStringIndices(base::Vector<const uint8_t> subject,
uint8_t pattern, std::vector<int>* indices,
unsigned int limit) { … }
void FindTwoByteStringIndices(const base::Vector<const base::uc16> subject,
base::uc16 pattern, std::vector<int>* indices,
unsigned int limit) { … }
template <typename SubjectChar, typename PatternChar>
void FindStringIndices(Isolate* isolate,
base::Vector<const SubjectChar> subject,
base::Vector<const PatternChar> pattern,
std::vector<int>* indices, unsigned int limit) { … }
void FindStringIndicesDispatch(Isolate* isolate, Tagged<String> subject,
Tagged<String> pattern,
std::vector<int>* indices, unsigned int limit) { … }
namespace {
std::vector<int>* GetRewoundRegexpIndicesList(Isolate* isolate) { … }
void TruncateRegexpIndicesList(Isolate* isolate) { … }
}
template <typename ResultSeqString>
V8_WARN_UNUSED_RESULT static Tagged<Object>
StringReplaceGlobalAtomRegExpWithString(
Isolate* isolate, DirectHandle<String> subject,
DirectHandle<JSRegExp> pattern_regexp, DirectHandle<String> replacement,
Handle<RegExpMatchInfo> last_match_info,
DirectHandle<AtomRegExpData> regexp_data) { … }
V8_WARN_UNUSED_RESULT static Tagged<Object> StringReplaceGlobalRegExpWithString(
Isolate* isolate, Handle<String> subject, DirectHandle<JSRegExp> regexp,
DirectHandle<RegExpData> regexp_data, Handle<String> replacement,
Handle<RegExpMatchInfo> last_match_info) { … }
template <typename ResultSeqString>
V8_WARN_UNUSED_RESULT static Tagged<Object>
StringReplaceGlobalRegExpWithEmptyString(
Isolate* isolate, Handle<String> subject, DirectHandle<JSRegExp> regexp,
DirectHandle<RegExpData> regexp_data,
Handle<RegExpMatchInfo> last_match_info) { … }
RUNTIME_FUNCTION(Runtime_StringSplit) { … }
namespace {
MaybeHandle<Object> RegExpExec(Isolate* isolate, DirectHandle<JSRegExp> regexp,
Handle<String> subject, int32_t index,
Handle<RegExpMatchInfo> last_match_info,
RegExp::ExecQuirks exec_quirks) { … }
MaybeHandle<Object> ExperimentalOneshotExec(
Isolate* isolate, DirectHandle<JSRegExp> regexp,
DirectHandle<String> subject, int32_t index,
Handle<RegExpMatchInfo> last_match_info, RegExp::ExecQuirks exec_quirks) { … }
}
RUNTIME_FUNCTION(Runtime_RegExpExec) { … }
RUNTIME_FUNCTION(Runtime_RegExpExecTreatMatchAtEndAsFailure) { … }
RUNTIME_FUNCTION(Runtime_RegExpExperimentalOneshotExec) { … }
RUNTIME_FUNCTION(
Runtime_RegExpExperimentalOneshotExecTreatMatchAtEndAsFailure) { … }
RUNTIME_FUNCTION(Runtime_RegExpBuildIndices) { … }
namespace {
class MatchInfoBackedMatch : public String::Match { … };
class VectorBackedMatch : public String::Match { … };
template <typename FunctionType,
typename = std::enable_if_t<std::is_function_v<Tagged<Object>(int)>>>
Handle<JSObject> ConstructNamedCaptureGroupsObject(
Isolate* isolate, DirectHandle<FixedArray> capture_map,
const FunctionType& f_get_capture) { … }
template <bool has_capture>
static Tagged<Object> SearchRegExpMultiple(
Isolate* isolate, Handle<String> subject, DirectHandle<JSRegExp> regexp,
DirectHandle<RegExpData> regexp_data,
Handle<RegExpMatchInfo> last_match_array) { … }
V8_WARN_UNUSED_RESULT MaybeHandle<String> RegExpReplace(
Isolate* isolate, Handle<JSRegExp> regexp, Handle<String> string,
Handle<String> replace) { … }
}
RUNTIME_FUNCTION(Runtime_RegExpExecMultiple) { … }
RUNTIME_FUNCTION(Runtime_StringReplaceNonGlobalRegExpWithFunction) { … }
namespace {
V8_WARN_UNUSED_RESULT MaybeHandle<Object> ToUint32(Isolate* isolate,
Handle<Object> object,
uint32_t* out) { … }
Handle<JSArray> NewJSArrayWithElements(Isolate* isolate,
Handle<FixedArray> elems,
int num_elems) { … }
}
RUNTIME_FUNCTION(Runtime_RegExpSplit) { … }
RUNTIME_FUNCTION(Runtime_RegExpReplaceRT) { … }
RUNTIME_FUNCTION(Runtime_RegExpInitializeAndCompile) { … }
RUNTIME_FUNCTION(Runtime_RegExpStringFromFlags) { … }
}
}