23 if (*recv == isolate->regexp_function()->prototype()) {
35 isolate->factory()->source_string()));
48 isolate->factory()->flags_string()));
61#define DEFINE_CAPTURE_GETTER(i) \
62 BUILTIN(RegExpCapture##i##Getter) { \
63 HandleScope scope(isolate); \
64 return *RegExpUtils::GenericCaptureGetter( \
65 isolate, isolate->regexp_last_match_info(), i); \
76#undef DEFINE_CAPTURE_GETTER
86 return IsUndefined(*obj, isolate) ?
ReadOnlyRoots(isolate).empty_string()
96 isolate->regexp_last_match_info()->set_last_input(*str);
107 isolate, isolate->regexp_last_match_info(), 0);
113 const int length = match_info->number_of_capture_registers();
119 const int last_capture = (length / 2) - 1;
130 const int start_index = match_info->capture(0);
132 return *isolate->factory()->NewSubString(last_subject, 0, start_index);
138 const int start_index = match_info->capture(1);
140 const int len = last_subject->length();
141 return *isolate->factory()->NewSubString(last_subject, start_index, len);
146constexpr uint8_t kNoEscape = 0;
147constexpr uint8_t kEscapeToHex = std::numeric_limits<uint8_t>::max();
148constexpr uint8_t GetAsciiEscape(
char c) {
210constexpr const uint8_t kAsciiEscapes[128]{
211#define GET_ASCII_ESCAPE(c) GetAsciiEscape(c),
213#undef GET_ASCII_ESCAPE
216template <
typename CharT>
217MaybeDirectHandle<String> RegExpEscapeImpl(Isolate* isolate,
218 base::OwnedVector<CharT> source) {
220 base::Vector<char> double_to_radix_buffer =
224 IncrementalStringBuilder escaped_builder(isolate);
225 if constexpr (
sizeof(CharT) == 2) {
226 escaped_builder.ChangeEncoding();
234 std::remove_const_t<CharT> first_c = source[0];
250 escaped_builder.AppendCStringLiteral(
"\\x");
251 std::string_view hex =
253 escaped_builder.AppendString(hex);
287 CharT cu = source[
i];
289 uint8_t cmd = kNoEscape;
292 cmd = kAsciiEscapes[cu];
294 if constexpr (
sizeof(CharT) == 2) {
296 if (
i + 1 < source.
size() &&
318 if (cmd == kNoEscape) {
321 escaped_builder.Append<CharT, CharT>(
cp);
326 escaped_builder.Append<CharT, CharT>(cu);
327 escaped_builder.Append<CharT, CharT>(source[
i]);
329 }
else if (cmd == kEscapeToHex) {
331 escaped_builder.AppendCStringLiteral(
cp <= 0xFF ?
"\\x" :
"\\u");
332 std::string_view hex =
334 escaped_builder.AppendString(hex);
337 escaped_builder.AppendCharacter(
'\\');
338 escaped_builder.AppendCharacter(cmd);
342 return escaped_builder.Finish();
353 if (!IsString(*value)) {
355 isolate, NewTypeError(MessageTemplate::kArgumentIsNonString,
356 isolate->factory()->input_string()));
360 if (str->length() == 0)
return ReadOnlyRoots(isolate).empty_string();
367 if (str->IsOneByteRepresentation()) {
374 isolate, escaped, RegExpEscapeImpl(isolate, std::move(copy)));
382 isolate, escaped, RegExpEscapeImpl(isolate, std::move(copy)));
#define DEFINE_CAPTURE_GETTER(i)
#define GET_ASCII_ESCAPE(c)
#define CHECK_RECEIVER(Type, name, method)
static bool IsSurrogatePair(int lead, int trail)
static int CombineSurrogatePair(uchar lead, uchar trail)
static bool IsTrailSurrogate(int code)
static bool IsLeadSurrogate(int code)
@ kRegExpPrototypeToString
MaybeDirectHandle< String > Finish()
V8_INLINE void AppendCharacter(uint8_t c)
V8_INLINE void AppendString(std::string_view str)
static V8_WARN_UNUSED_RESULT MaybeHandle< Object > GetProperty(Isolate *isolate, DirectHandle< JSReceiver > receiver, const char *key)
static V8_WARN_UNUSED_RESULT HandleType< String >::MaybeType ToString(Isolate *isolate, HandleType< T > input)
static Handle< String > GenericCaptureGetter(Isolate *isolate, DirectHandle< RegExpMatchInfo > match_info, int capture, bool *ok=nullptr)
static V8_INLINE HandleType< String > Flatten(Isolate *isolate, HandleType< T > string, AllocationType allocation=AllocationType::kYoung)
#define ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, dst, call)
#define THROW_NEW_ERROR_RETURN_FAILURE(isolate, call)
#define RETURN_RESULT_OR_FAILURE(isolate, call)
base::Vector< const DirectHandle< Object > > args
InstructionOperand source
constexpr Vector< T > ArrayVector(T(&arr)[N])
OwnedVector< T > OwnedCopyOf(const T *data, size_t size)
constexpr bool IsAscii(base::uc32 c)
bool IsWhiteSpaceOrLineTerminator(base::uc32 c)
constexpr int kDoubleToRadixMaxChars
constexpr bool IsAlphaNumeric(base::uc32 c)
std::string_view DoubleToRadixStringView(double value, int radix, base::Vector< char > buffer)
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
#define DCHECK(condition)
#define DCHECK_LT(v1, v2)
#define DCHECK_EQ(v1, v2)
#define INT_0_TO_127_LIST(V)