Skip to content
forked from v8/v8

Commit

Permalink
[M108-LTS][inspector] Create shared regexp object for regex breakpoints
Browse files Browse the repository at this point in the history
The patch hoists creation of regex object out of the script loop (when
setting breakpoints via an url regexp).

(cherry picked from commit 79b94e8)

Bug: chromium:1422830
Change-Id: Ifc6117ad6c9de41844c2531c6c7d9f8fa4b27627
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4350697
Commit-Queue: Jaroslav Sevcik <jarin@chromium.org>
Cr-Original-Commit-Position: refs/branch-heads/11.2@{v8#19}
Cr-Original-Branched-From: 755511a-refs/heads/11.2.214@{#1}
Cr-Original-Branched-From: e6b1cce-refs/heads/main@{#86014}
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4685219
Reviewed-by: Victor Gabriel Savu <vsavu@google.com>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Zakhar Voit <voit@google.com>
Cr-Commit-Position: refs/branch-heads/10.8@{v8#76}
Cr-Branched-From: f1bc03f-refs/heads/10.8.168@{#1}
Cr-Branched-From: 237de89-refs/heads/main@{#83672}
  • Loading branch information
zakharvoit authored and V8 LUCI CQ committed Jul 21, 2023
1 parent 6bc81d0 commit 8364240
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions src/inspector/v8-debugger-agent-impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -501,24 +501,42 @@ Response V8DebuggerAgentImpl::setSkipAllPauses(bool skip) {
return Response::Success();
}

static bool matches(V8InspectorImpl* inspector, const V8DebuggerScript& script,
BreakpointType type, const String16& selector) {
switch (type) {
case BreakpointType::kByUrl:
return script.sourceURL() == selector;
case BreakpointType::kByScriptHash:
return script.hash() == selector;
case BreakpointType::kByUrlRegex: {
V8Regex regex(inspector, selector, true);
return regex.match(script.sourceURL()) != -1;
namespace {

class Matcher {
public:
Matcher(V8InspectorImpl* inspector, BreakpointType type,
const String16& selector)
: type_(type), selector_(selector) {
if (type == BreakpointType::kByUrlRegex) {
regex_ = std::make_unique<V8Regex>(inspector, selector, true);
}
case BreakpointType::kByScriptId: {
return script.scriptId() == selector;
}

bool matches(const V8DebuggerScript& script) {
switch (type_) {
case BreakpointType::kByUrl:
return script.sourceURL() == selector_;
case BreakpointType::kByScriptHash:
return script.hash() == selector_;
case BreakpointType::kByUrlRegex: {
return regex_->match(script.sourceURL()) != -1;
}
case BreakpointType::kByScriptId: {
return script.scriptId() == selector_;
}
default:
return false;
}
default:
return false;
}
}

private:
std::unique_ptr<V8Regex> regex_;
BreakpointType type_;
const String16& selector_;
};

} // namespace

Response V8DebuggerAgentImpl::setBreakpointByUrl(
int lineNumber, Maybe<String16> optionalURL,
Expand Down Expand Up @@ -557,6 +575,9 @@ Response V8DebuggerAgentImpl::setBreakpointByUrl(
type = BreakpointType::kByScriptHash;
}

// Note: This constructor can call into JavaScript.
Matcher matcher(m_inspector, type, selector);

String16 condition = optionalCondition.fromMaybe(String16());
String16 breakpointId =
generateBreakpointId(type, selector, lineNumber, columnNumber);
Expand Down Expand Up @@ -587,7 +608,7 @@ Response V8DebuggerAgentImpl::setBreakpointByUrl(

String16 hint;
for (const auto& script : m_scripts) {
if (!matches(m_inspector, *script.second, type, selector)) continue;
if (!matcher.matches(*script.second)) continue;
if (!hint.isEmpty()) {
adjustBreakpointLocation(*script.second, hint, &lineNumber,
&columnNumber);
Expand Down Expand Up @@ -683,6 +704,7 @@ Response V8DebuggerAgentImpl::removeBreakpoint(const String16& breakpointId) {
if (!parseBreakpointId(breakpointId, &type, &selector)) {
return Response::Success();
}
Matcher matcher(m_inspector, type, selector);
protocol::DictionaryValue* breakpoints = nullptr;
switch (type) {
case BreakpointType::kByUrl: {
Expand Down Expand Up @@ -719,8 +741,7 @@ Response V8DebuggerAgentImpl::removeBreakpoint(const String16& breakpointId) {
// not Wasm breakpoint.
std::vector<V8DebuggerScript*> scripts;
for (const auto& scriptIter : m_scripts) {
const bool scriptSelectorMatch =
matches(m_inspector, *scriptIter.second, type, selector);
const bool scriptSelectorMatch = matcher.matches(*scriptIter.second);
const bool isInstrumentation =
type == BreakpointType::kInstrumentationBreakpoint;
if (!scriptSelectorMatch && !isInstrumentation) continue;
Expand Down Expand Up @@ -1874,8 +1895,9 @@ void V8DebuggerAgentImpl::didParseSource(
int columnNumber = 0;
parseBreakpointId(breakpointId, &type, &selector, &lineNumber,
&columnNumber);
Matcher matcher(m_inspector, type, selector);

if (!matches(m_inspector, *scriptRef, type, selector)) continue;
if (!matcher.matches(*scriptRef)) continue;
String16 condition;
breakpointWithCondition.second->asString(&condition);
String16 hint;
Expand Down

0 comments on commit 8364240

Please sign in to comment.