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

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.cc » ('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 namespace {
8930 int GetSmiValue(i::Isolate* isolate, i::Handle<i::FixedArray> array,
8931 int index) {
8932 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.
8933 }
8934 } // namespace
8935
8936 bool DebugInterface::Script::GetPossibleBreakpoints(
8937 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
8938 std::vector<Location>* locations) const {
8939 CHECK(!start.IsEmpty());
8940 i::Handle<i::Script> script = Utils::OpenHandle(this);
8941
8942 i::Script::InitLineEnds(script);
8943 CHECK(script->line_ends()->IsFixedArray());
8944 i::Isolate* isolate = script->GetIsolate();
8945 i::Handle<i::FixedArray> line_ends =
8946 i::Handle<i::FixedArray>::cast(i::handle(script->line_ends(), isolate));
8947 CHECK(line_ends->length());
8948
8949 int start_offset = GetSourcePosition(start);
8950 int end_offset;
8951 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.
8952 end_offset = GetSmiValue(isolate, line_ends, line_ends->length() - 1) + 1;
8953 else
8954 end_offset = GetSourcePosition(end);
8955 if (start_offset >= end_offset) return true;
8956
8957 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.
8958 if (!isolate->debug()->GetPossibleBreakpoints(script, start_offset,
8959 end_offset, &offsets)) {
8960 return false;
8961 }
8962 std::set<int> unique_offsets;
8963 for (size_t i = 0; i < offsets.size(); ++i) unique_offsets.insert(offsets[i]);
8964
8965 int current_line_end_index = 0;
8966 for (const auto& it : unique_offsets) {
8967 int offset = it;
8968 while (offset > GetSmiValue(isolate, line_ends, current_line_end_index)) {
8969 ++current_line_end_index;
8970 CHECK(current_line_end_index < line_ends->length());
8971 }
8972 int line_offset = 0;
8973
8974 if (current_line_end_index > 0) {
8975 line_offset =
8976 GetSmiValue(isolate, line_ends, current_line_end_index - 1) + 1;
8977 }
8978 locations->push_back(
8979 Location(current_line_end_index, offset - line_offset));
8980 }
8981 return true;
8982 }
8983
8984 int DebugInterface::Script::GetSourcePosition(const Location& location) const {
8985 int line = location.GetLineNumber();
8986 int column = location.GetColumnNumber();
8987
8988 i::Handle<i::Script> script = Utils::OpenHandle(this);
8989 i::Script::InitLineEnds(script);
8990 CHECK(script->line_ends()->IsFixedArray());
8991 i::Isolate* isolate = script->GetIsolate();
8992 i::Handle<i::FixedArray> line_ends =
8993 i::Handle<i::FixedArray>::cast(i::handle(script->line_ends(), isolate));
8994 CHECK(line_ends->length());
8995 if (line >= line_ends->length())
8996 return GetSmiValue(isolate, line_ends, line_ends->length() - 1);
8997 int line_offset = GetSmiValue(isolate, line_ends, line);
8998 if (line == 0) return std::min(column, line_offset);
8999 int prev_line_offset = GetSmiValue(isolate, line_ends, line - 1);
9000 return std::min(prev_line_offset + column + 1, line_offset);
9001 }
9002
8929 MaybeLocal<DebugInterface::Script> DebugInterface::Script::Wrap( 9003 MaybeLocal<DebugInterface::Script> DebugInterface::Script::Wrap(
8930 v8::Isolate* v8_isolate, v8::Local<v8::Object> script) { 9004 v8::Isolate* v8_isolate, v8::Local<v8::Object> script) {
8931 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 9005 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
8932 ENTER_V8(isolate); 9006 ENTER_V8(isolate);
8933 i::HandleScope handle_scope(isolate); 9007 i::HandleScope handle_scope(isolate);
8934 i::Handle<i::JSReceiver> script_receiver(Utils::OpenHandle(*script)); 9008 i::Handle<i::JSReceiver> script_receiver(Utils::OpenHandle(*script));
8935 if (!script_receiver->IsJSValue()) return MaybeLocal<Script>(); 9009 if (!script_receiver->IsJSValue()) return MaybeLocal<Script>();
8936 i::Handle<i::Object> script_value( 9010 i::Handle<i::Object> script_value(
8937 i::Handle<i::JSValue>::cast(script_receiver)->value(), isolate); 9011 i::Handle<i::JSValue>::cast(script_receiver)->value(), isolate);
8938 if (!script_value->IsScript()) { 9012 if (!script_value->IsScript()) {
8939 return MaybeLocal<Script>(); 9013 return MaybeLocal<Script>();
8940 } 9014 }
8941 i::Handle<i::Script> script_obj = i::Handle<i::Script>::cast(script_value); 9015 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>(); 9016 if (script_obj->type() != i::Script::TYPE_NORMAL) return MaybeLocal<Script>();
8943 return ToApiHandle<DebugInterface::Script>( 9017 return ToApiHandle<DebugInterface::Script>(
8944 handle_scope.CloseAndEscape(script_obj)); 9018 handle_scope.CloseAndEscape(script_obj));
8945 } 9019 }
8946 9020
9021 DebugInterface::Location::Location(int lineNumber, int columnNumber)
9022 : lineNumber_(lineNumber), columnNumber_(columnNumber) {
9023 CHECK(lineNumber >= 0);
9024 CHECK(columnNumber >= 0);
9025 }
9026
9027 DebugInterface::Location::Location() : lineNumber_(-1), columnNumber_(-1) {}
9028
9029 int DebugInterface::Location::GetLineNumber() const {
9030 CHECK(lineNumber_ >= 0);
9031 return lineNumber_;
9032 }
9033
9034 int DebugInterface::Location::GetColumnNumber() const {
9035 CHECK(columnNumber_ >= 0);
9036 return columnNumber_;
9037 }
9038
9039 bool DebugInterface::Location::IsEmpty() const {
9040 return lineNumber_ == -1 && columnNumber_ == -1;
9041 }
9042
8947 void DebugInterface::GetLoadedScripts( 9043 void DebugInterface::GetLoadedScripts(
8948 v8::Isolate* v8_isolate, 9044 v8::Isolate* v8_isolate,
8949 PersistentValueVector<DebugInterface::Script>& scripts) { 9045 PersistentValueVector<DebugInterface::Script>& scripts) {
8950 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 9046 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
8951 ENTER_V8(isolate); 9047 ENTER_V8(isolate);
8952 i::HandleScope handle_scope(isolate); 9048 i::HandleScope handle_scope(isolate);
8953 i::Handle<i::FixedArray> instances = isolate->debug()->GetLoadedScripts(); 9049 i::Handle<i::FixedArray> instances = isolate->debug()->GetLoadedScripts();
8954 for (int i = 0; i < instances->length(); i++) { 9050 for (int i = 0; i < instances->length(); i++) {
8955 i::Handle<i::Script> script = 9051 i::Handle<i::Script> script =
8956 i::Handle<i::Script>(i::Script::cast(instances->get(i))); 9052 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 = 9736 Address callback_address =
9641 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 9737 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9642 VMState<EXTERNAL> state(isolate); 9738 VMState<EXTERNAL> state(isolate);
9643 ExternalCallbackScope call_scope(isolate, callback_address); 9739 ExternalCallbackScope call_scope(isolate, callback_address);
9644 callback(info); 9740 callback(info);
9645 } 9741 }
9646 9742
9647 9743
9648 } // namespace internal 9744 } // namespace internal
9649 } // namespace v8 9745 } // namespace v8
OLDNEW
« 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