5 #include "src/inspector/v8-regex.h" 9 #include "src/inspector/string-util.h" 10 #include "src/inspector/v8-inspector-impl.h" 12 #include "include/v8-inspector.h" 16 V8Regex::V8Regex(V8InspectorImpl* inspector,
const String16& pattern,
17 bool caseSensitive,
bool multiline)
18 : m_inspector(inspector) {
19 v8::Isolate* isolate = m_inspector->isolate();
23 v8::TryCatch tryCatch(isolate);
25 unsigned flags = v8::RegExp::kNone;
26 if (!caseSensitive) flags |= v8::RegExp::kIgnoreCase;
27 if (multiline) flags |= v8::RegExp::kMultiline;
31 static_cast<v8::RegExp::Flags>(flags))
33 m_regex.Reset(isolate, regex);
34 else if (tryCatch.HasCaught())
35 m_errorMessage = toProtocolString(isolate, tryCatch.Message()->Get());
37 m_errorMessage =
"Internal error";
40 int V8Regex::match(
const String16&
string,
int startFrom,
41 int* matchLength)
const {
42 if (matchLength) *matchLength = 0;
44 if (m_regex.IsEmpty() ||
string.isEmpty())
return -1;
47 if (
string.length() > INT_MAX)
return -1;
49 v8::Isolate* isolate = m_inspector->isolate();
53 v8::MicrotasksScope microtasks(isolate,
54 v8::MicrotasksScope::kDoNotRunMicrotasks);
55 v8::TryCatch tryCatch(isolate);
59 if (!regex->Get(context, toV8StringInternalized(isolate,
"exec"))
63 toV8String(isolate,
string.substring(startFrom))};
66 ->Call(context, regex, arraysize(argv), argv)
78 if (!returnValue->
IsArray())
return -1;
82 if (!result->Get(context, toV8StringInternalized(isolate,
"index"))
83 .ToLocal(&matchOffset))
87 if (!result->Get(context, 0).ToLocal(&match))
return -1;
V8_INLINE bool IsEmpty() const
V8_INLINE Local< S > As() const
V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local< S > *out) const
static V8_WARN_UNUSED_RESULT MaybeLocal< RegExp > New(Local< Context > context, Local< String > pattern, Flags flags)