Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: src/api.cc

Issue 2465553003: [inspector] added Debugger.getPossibleBreakpoints method (Closed)
Patch Set: it works Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/debug/debug.h » ('j') | src/debug/debug.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index b7a5b2e4ec45e1642a6ad578e9f98604f490d806..5caf9b25f6b0d5e0ab82336f6e8056e5ed075829 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -8926,6 +8926,51 @@ MaybeLocal<String> DebugInterface::Script::Source() const {
handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value)));
}
+bool DebugInterface::Script::GetPossibleBreakpoints(
+ int start_line, int start_column, int end_line, int end_column,
+ std::vector<int>& positions) const {
+ i::Handle<i::Script> script = Utils::OpenHandle(this);
+ int start_offset = Offset(start_line, start_column);
+ int end_offset;
+ if (end_line == -1 || end_column == -1)
+ end_offset = Offset(static_cast<int>(LineEnds().size()), 0);
+ else
+ end_offset = Offset(end_line, end_column);
+ if (start_offset >= end_offset) return true;
+
+ i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
+ std::vector<int> offsets;
+ if (!isolate->debug()->GetPossibleBreakpoints(script, start_offset,
+ end_offset, offsets))
+ return false;
+ std::set<int> unique_offsets;
+ for (size_t i = 0; i < offsets.size(); ++i) unique_offsets.insert(offsets[i]);
+
+ int current_line_end_index = 0;
+ std::vector<int> line_endings = LineEnds();
+ for (const auto& it : unique_offsets) {
+ int offset = it;
+ while (offset > line_endings[current_line_end_index] &&
+ current_line_end_index < line_endings.size())
+ ++current_line_end_index;
+ CHECK(current_line_end_index < line_endings.size());
+ positions.push_back(current_line_end_index);
+ positions.push_back(offset -
+ (current_line_end_index > 0
+ ? (line_endings[current_line_end_index - 1] + 1)
+ : 0));
+ }
+ return true;
+}
+
+int DebugInterface::Script::Offset(int line, int column) const {
+ i::Handle<i::Script> script = Utils::OpenHandle(this);
+ std::vector<int> line_endings = LineEnds();
+ if (line == 0) return std::min(column, line_endings[line]);
+ if (line >= line_endings.size()) return line_endings.back();
+ return std::min(line_endings[line - 1] + column + 1, line_endings[line]);
+}
+
MaybeLocal<DebugInterface::Script> DebugInterface::Script::Wrap(
v8::Isolate* v8_isolate, v8::Local<v8::Object> script) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
« no previous file with comments | « no previous file | src/debug/debug.h » ('j') | src/debug/debug.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698