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

Unified Diff: src/api.cc

Issue 2465553003: [inspector] added Debugger.getPossibleBreakpoints method (Closed)
Patch Set: addressed comments 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-interface.h » ('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..73ee8cd416d8a9a4721342000907a330d3727b34 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -8926,6 +8926,54 @@ MaybeLocal<String> DebugInterface::Script::Source() const {
handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value)));
}
+bool DebugInterface::Script::GetPossibleBreakpoints(
+ const Location& start, const Location& end,
+ std::vector<Location>* locations) const {
+ CHECK(!start.IsEmpty());
+ i::Handle<i::Script> script = Utils::OpenHandle(this);
+ int start_offset = GetSourcePosition(start);
+ int end_offset;
+ if (end.IsEmpty())
+ end_offset = LineEnds().back() + 1;
+ else
+ end_offset = GetSourcePosition(end);
+ 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] &&
dgozman 2016/11/03 21:13:12 while (offset > ...) { index++; CHECK(index <
kozy 2016/11/03 22:17:13 Done.
+ current_line_end_index < line_endings.size())
+ ++current_line_end_index;
+ CHECK(current_line_end_index < line_endings.size());
+ int line_offset = current_line_end_index > 0
+ ? (line_endings[current_line_end_index - 1] + 1)
+ : 0;
+ locations->push_back(
+ Location(current_line_end_index, offset - line_offset));
+ }
+ return true;
+}
+
+int DebugInterface::Script::GetSourcePosition(const Location& location) const {
+ i::Handle<i::Script> script = Utils::OpenHandle(this);
+ std::vector<int> line_endings = LineEnds();
dgozman 2016/11/03 21:13:12 Can we cache line endings?
kozy 2016/11/03 22:17:13 Done.
+ int line = location.GetLineNumber();
+ int column = location.GetColumnNumber();
+ 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);
@@ -8944,6 +8992,27 @@ MaybeLocal<DebugInterface::Script> DebugInterface::Script::Wrap(
handle_scope.CloseAndEscape(script_obj));
}
+DebugInterface::Script::Location::Location(int lineNumber, int columnNumber)
+ : lineNumber_(lineNumber), columnNumber_(columnNumber) {
+ CHECK(lineNumber >= 0);
+ CHECK(columnNumber >= 0);
+}
+DebugInterface::Script::Location::Location()
+ : lineNumber_(-1), columnNumber_(-1) {}
+
+int DebugInterface::Script::Location::GetLineNumber() const {
+ CHECK(lineNumber_ >= 0);
+ return lineNumber_;
+}
+int DebugInterface::Script::Location::GetColumnNumber() const {
dgozman 2016/11/03 21:13:12 where are the empty lines?
kozy 2016/11/03 22:17:13 Done.
+ CHECK(columnNumber_ >= 0);
+ return columnNumber_;
+}
+
+bool DebugInterface::Script::Location::IsEmpty() const {
+ return lineNumber_ == -1 && columnNumber_ == -1;
+}
+
void DebugInterface::GetLoadedScripts(
v8::Isolate* v8_isolate,
PersistentValueVector<DebugInterface::Script>& scripts) {
« no previous file with comments | « no previous file | src/debug/debug.h » ('j') | src/debug/debug-interface.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698