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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/debug/debug.h » ('j') | src/debug/debug-interface.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 8908 matching lines...) Expand 10 before | Expand all | Expand 10 after
8919 MaybeLocal<String> DebugInterface::Script::Source() const { 8919 MaybeLocal<String> DebugInterface::Script::Source() const {
8920 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 8920 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
8921 i::HandleScope handle_scope(isolate); 8921 i::HandleScope handle_scope(isolate);
8922 i::Handle<i::Script> script = Utils::OpenHandle(this); 8922 i::Handle<i::Script> script = Utils::OpenHandle(this);
8923 i::Handle<i::Object> value(script->source(), isolate); 8923 i::Handle<i::Object> value(script->source(), isolate);
8924 if (!value->IsString()) return MaybeLocal<String>(); 8924 if (!value->IsString()) return MaybeLocal<String>();
8925 return Utils::ToLocal( 8925 return Utils::ToLocal(
8926 handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value))); 8926 handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value)));
8927 } 8927 }
8928 8928
8929 bool DebugInterface::Script::GetPossibleBreakpoints(
8930 const Location& start, const Location& end,
8931 std::vector<Location>* locations) const {
8932 CHECK(!start.IsEmpty());
8933 i::Handle<i::Script> script = Utils::OpenHandle(this);
8934 int start_offset = GetSourcePosition(start);
8935 int end_offset;
8936 if (end.IsEmpty())
8937 end_offset = LineEnds().back() + 1;
8938 else
8939 end_offset = GetSourcePosition(end);
8940 if (start_offset >= end_offset) return true;
8941
8942 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
8943 std::vector<int> offsets;
8944 if (!isolate->debug()->GetPossibleBreakpoints(script, start_offset,
8945 end_offset, &offsets))
8946 return false;
8947 std::set<int> unique_offsets;
8948 for (size_t i = 0; i < offsets.size(); ++i) unique_offsets.insert(offsets[i]);
8949
8950 int current_line_end_index = 0;
8951 std::vector<int> line_endings = LineEnds();
8952 for (const auto& it : unique_offsets) {
8953 int offset = it;
8954 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.
8955 current_line_end_index < line_endings.size())
8956 ++current_line_end_index;
8957 CHECK(current_line_end_index < line_endings.size());
8958 int line_offset = current_line_end_index > 0
8959 ? (line_endings[current_line_end_index - 1] + 1)
8960 : 0;
8961 locations->push_back(
8962 Location(current_line_end_index, offset - line_offset));
8963 }
8964 return true;
8965 }
8966
8967 int DebugInterface::Script::GetSourcePosition(const Location& location) const {
8968 i::Handle<i::Script> script = Utils::OpenHandle(this);
8969 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.
8970 int line = location.GetLineNumber();
8971 int column = location.GetColumnNumber();
8972 if (line == 0) return std::min(column, line_endings[line]);
8973 if (line >= line_endings.size()) return line_endings.back();
8974 return std::min(line_endings[line - 1] + column + 1, line_endings[line]);
8975 }
8976
8929 MaybeLocal<DebugInterface::Script> DebugInterface::Script::Wrap( 8977 MaybeLocal<DebugInterface::Script> DebugInterface::Script::Wrap(
8930 v8::Isolate* v8_isolate, v8::Local<v8::Object> script) { 8978 v8::Isolate* v8_isolate, v8::Local<v8::Object> script) {
8931 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 8979 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
8932 ENTER_V8(isolate); 8980 ENTER_V8(isolate);
8933 i::HandleScope handle_scope(isolate); 8981 i::HandleScope handle_scope(isolate);
8934 i::Handle<i::JSReceiver> script_receiver(Utils::OpenHandle(*script)); 8982 i::Handle<i::JSReceiver> script_receiver(Utils::OpenHandle(*script));
8935 if (!script_receiver->IsJSValue()) return MaybeLocal<Script>(); 8983 if (!script_receiver->IsJSValue()) return MaybeLocal<Script>();
8936 i::Handle<i::Object> script_value( 8984 i::Handle<i::Object> script_value(
8937 i::Handle<i::JSValue>::cast(script_receiver)->value(), isolate); 8985 i::Handle<i::JSValue>::cast(script_receiver)->value(), isolate);
8938 if (!script_value->IsScript()) { 8986 if (!script_value->IsScript()) {
8939 return MaybeLocal<Script>(); 8987 return MaybeLocal<Script>();
8940 } 8988 }
8941 i::Handle<i::Script> script_obj = i::Handle<i::Script>::cast(script_value); 8989 i::Handle<i::Script> script_obj = i::Handle<i::Script>::cast(script_value);
8942 if (script_obj->type() != i::Script::TYPE_NORMAL) return MaybeLocal<Script>(); 8990 if (script_obj->type() != i::Script::TYPE_NORMAL) return MaybeLocal<Script>();
8943 return ToApiHandle<DebugInterface::Script>( 8991 return ToApiHandle<DebugInterface::Script>(
8944 handle_scope.CloseAndEscape(script_obj)); 8992 handle_scope.CloseAndEscape(script_obj));
8945 } 8993 }
8946 8994
8995 DebugInterface::Script::Location::Location(int lineNumber, int columnNumber)
8996 : lineNumber_(lineNumber), columnNumber_(columnNumber) {
8997 CHECK(lineNumber >= 0);
8998 CHECK(columnNumber >= 0);
8999 }
9000 DebugInterface::Script::Location::Location()
9001 : lineNumber_(-1), columnNumber_(-1) {}
9002
9003 int DebugInterface::Script::Location::GetLineNumber() const {
9004 CHECK(lineNumber_ >= 0);
9005 return lineNumber_;
9006 }
9007 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.
9008 CHECK(columnNumber_ >= 0);
9009 return columnNumber_;
9010 }
9011
9012 bool DebugInterface::Script::Location::IsEmpty() const {
9013 return lineNumber_ == -1 && columnNumber_ == -1;
9014 }
9015
8947 void DebugInterface::GetLoadedScripts( 9016 void DebugInterface::GetLoadedScripts(
8948 v8::Isolate* v8_isolate, 9017 v8::Isolate* v8_isolate,
8949 PersistentValueVector<DebugInterface::Script>& scripts) { 9018 PersistentValueVector<DebugInterface::Script>& scripts) {
8950 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 9019 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
8951 ENTER_V8(isolate); 9020 ENTER_V8(isolate);
8952 i::HandleScope handle_scope(isolate); 9021 i::HandleScope handle_scope(isolate);
8953 i::Handle<i::FixedArray> instances = isolate->debug()->GetLoadedScripts(); 9022 i::Handle<i::FixedArray> instances = isolate->debug()->GetLoadedScripts();
8954 for (int i = 0; i < instances->length(); i++) { 9023 for (int i = 0; i < instances->length(); i++) {
8955 i::Handle<i::Script> script = 9024 i::Handle<i::Script> script =
8956 i::Handle<i::Script>(i::Script::cast(instances->get(i))); 9025 i::Handle<i::Script>(i::Script::cast(instances->get(i)));
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
9640 Address callback_address = 9709 Address callback_address =
9641 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 9710 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9642 VMState<EXTERNAL> state(isolate); 9711 VMState<EXTERNAL> state(isolate);
9643 ExternalCallbackScope call_scope(isolate, callback_address); 9712 ExternalCallbackScope call_scope(isolate, callback_address);
9644 callback(info); 9713 callback(info);
9645 } 9714 }
9646 9715
9647 9716
9648 } // namespace internal 9717 } // namespace internal
9649 } // namespace v8 9718 } // namespace v8
OLDNEW
« 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