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

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.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..5059d0a0b9e55c7198585e872905cb3136eb8052 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -8926,6 +8926,80 @@ MaybeLocal<String> DebugInterface::Script::Source() const {
handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value)));
}
+namespace {
+int GetSmiValue(i::Isolate* isolate, i::Handle<i::FixedArray> array,
+ int index) {
+ return array->GetValueChecked<i::Smi>(isolate, index)->value();
Yang 2016/11/04 12:22:58 Let's just use Smi::cast(array->get(index))->value
kozy 2016/11/04 14:48:38 Done.
+}
+} // namespace
+
+bool DebugInterface::Script::GetPossibleBreakpoints(
+ const Location& start, const Location& end,
Yang 2016/11/04 12:22:58 Is this location with or without the line_offset a
kozy 2016/11/04 14:48:38 This Location contains line_offset and column_offs
Yang 2016/11/04 14:53:00 yes, but arent line_ends initialized without offse
kozy 2016/11/04 15:04:01 As I found line_ends contains offset of \n in sour
+ std::vector<Location>* locations) const {
+ CHECK(!start.IsEmpty());
+ i::Handle<i::Script> script = Utils::OpenHandle(this);
+
+ i::Script::InitLineEnds(script);
+ CHECK(script->line_ends()->IsFixedArray());
+ i::Isolate* isolate = script->GetIsolate();
+ i::Handle<i::FixedArray> line_ends =
+ i::Handle<i::FixedArray>::cast(i::handle(script->line_ends(), isolate));
+ CHECK(line_ends->length());
+
+ int start_offset = GetSourcePosition(start);
+ int end_offset;
+ if (end.IsEmpty())
Yang 2016/11/04 12:22:58 can we have brackets around the then-body and the
kozy 2016/11/04 14:48:38 Done.
+ end_offset = GetSmiValue(isolate, line_ends, line_ends->length() - 1) + 1;
+ else
+ end_offset = GetSourcePosition(end);
+ if (start_offset >= end_offset) return true;
+
+ std::vector<int> offsets;
Yang 2016/11/04 12:22:58 why don't we pass an std::set to GetPossibleBreakp
kozy 2016/11/04 14:48:38 Done.
+ 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;
+ for (const auto& it : unique_offsets) {
+ int offset = it;
+ while (offset > GetSmiValue(isolate, line_ends, current_line_end_index)) {
+ ++current_line_end_index;
+ CHECK(current_line_end_index < line_ends->length());
+ }
+ int line_offset = 0;
+
+ if (current_line_end_index > 0) {
+ line_offset =
+ GetSmiValue(isolate, line_ends, current_line_end_index - 1) + 1;
+ }
+ locations->push_back(
+ Location(current_line_end_index, offset - line_offset));
+ }
+ return true;
+}
+
+int DebugInterface::Script::GetSourcePosition(const Location& location) const {
+ int line = location.GetLineNumber();
+ int column = location.GetColumnNumber();
+
+ i::Handle<i::Script> script = Utils::OpenHandle(this);
+ i::Script::InitLineEnds(script);
+ CHECK(script->line_ends()->IsFixedArray());
+ i::Isolate* isolate = script->GetIsolate();
+ i::Handle<i::FixedArray> line_ends =
+ i::Handle<i::FixedArray>::cast(i::handle(script->line_ends(), isolate));
+ CHECK(line_ends->length());
+ if (line >= line_ends->length())
+ return GetSmiValue(isolate, line_ends, line_ends->length() - 1);
+ int line_offset = GetSmiValue(isolate, line_ends, line);
+ if (line == 0) return std::min(column, line_offset);
+ int prev_line_offset = GetSmiValue(isolate, line_ends, line - 1);
+ return std::min(prev_line_offset + column + 1, line_offset);
+}
+
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 +9018,28 @@ MaybeLocal<DebugInterface::Script> DebugInterface::Script::Wrap(
handle_scope.CloseAndEscape(script_obj));
}
+DebugInterface::Location::Location(int lineNumber, int columnNumber)
+ : lineNumber_(lineNumber), columnNumber_(columnNumber) {
+ CHECK(lineNumber >= 0);
+ CHECK(columnNumber >= 0);
+}
+
+DebugInterface::Location::Location() : lineNumber_(-1), columnNumber_(-1) {}
+
+int DebugInterface::Location::GetLineNumber() const {
+ CHECK(lineNumber_ >= 0);
+ return lineNumber_;
+}
+
+int DebugInterface::Location::GetColumnNumber() const {
+ CHECK(columnNumber_ >= 0);
+ return columnNumber_;
+}
+
+bool DebugInterface::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.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698