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

Side by Side Diff: src/api.cc

Issue 2465553003: [inspector] added Debugger.getPossibleBreakpoints method (Closed)
Patch Set: minor improvement 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') | test/inspector/task-runner.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 8932 matching lines...) Expand 10 before | Expand all | Expand 10 after
8943 MaybeLocal<String> DebugInterface::Script::Source() const { 8943 MaybeLocal<String> DebugInterface::Script::Source() const {
8944 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 8944 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
8945 i::HandleScope handle_scope(isolate); 8945 i::HandleScope handle_scope(isolate);
8946 i::Handle<i::Script> script = Utils::OpenHandle(this); 8946 i::Handle<i::Script> script = Utils::OpenHandle(this);
8947 i::Handle<i::Object> value(script->source(), isolate); 8947 i::Handle<i::Object> value(script->source(), isolate);
8948 if (!value->IsString()) return MaybeLocal<String>(); 8948 if (!value->IsString()) return MaybeLocal<String>();
8949 return Utils::ToLocal( 8949 return Utils::ToLocal(
8950 handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value))); 8950 handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value)));
8951 } 8951 }
8952 8952
8953 namespace {
8954 int GetSmiValue(i::Handle<i::FixedArray> array, int index) {
8955 return i::Smi::cast(array->get(index))->value();
8956 }
8957 } // namespace
8958
8959 bool DebugInterface::Script::GetPossibleBreakpoints(
8960 const Location& start, const Location& end,
8961 std::vector<Location>* locations) const {
8962 CHECK(!start.IsEmpty());
8963 i::Handle<i::Script> script = Utils::OpenHandle(this);
8964
8965 i::Script::InitLineEnds(script);
8966 CHECK(script->line_ends()->IsFixedArray());
8967 i::Isolate* isolate = script->GetIsolate();
8968 i::Handle<i::FixedArray> line_ends =
8969 i::Handle<i::FixedArray>::cast(i::handle(script->line_ends(), isolate));
8970 CHECK(line_ends->length());
8971
8972 int start_offset = GetSourcePosition(start);
8973 int end_offset;
8974 if (end.IsEmpty()) {
8975 end_offset = GetSmiValue(line_ends, line_ends->length() - 1) + 1;
8976 } else {
8977 end_offset = GetSourcePosition(end);
8978 }
8979 if (start_offset >= end_offset) return true;
8980
8981 std::set<int> offsets;
8982 if (!isolate->debug()->GetPossibleBreakpoints(script, start_offset,
8983 end_offset, &offsets)) {
8984 return false;
8985 }
8986
8987 int current_line_end_index = 0;
8988 for (const auto& it : offsets) {
8989 int offset = it;
8990 while (offset > GetSmiValue(line_ends, current_line_end_index)) {
8991 ++current_line_end_index;
8992 CHECK(current_line_end_index < line_ends->length());
8993 }
8994 int line_offset = 0;
8995
8996 if (current_line_end_index > 0) {
8997 line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1;
8998 }
8999 locations->push_back(Location(
9000 current_line_end_index + script->line_offset(),
9001 offset - line_offset +
9002 (current_line_end_index == 0 ? script->column_offset() : 0)));
9003 }
9004 return true;
9005 }
9006
9007 int DebugInterface::Script::GetSourcePosition(const Location& location) const {
9008 i::Handle<i::Script> script = Utils::OpenHandle(this);
9009
9010 int line = std::max(location.GetLineNumber() - script->line_offset(), 0);
9011 int column = location.GetColumnNumber();
9012 if (line == 0) {
9013 column = std::max(0, column - script->column_offset());
9014 }
9015
9016 i::Script::InitLineEnds(script);
9017 CHECK(script->line_ends()->IsFixedArray());
9018 i::Handle<i::FixedArray> line_ends = i::Handle<i::FixedArray>::cast(
9019 i::handle(script->line_ends(), script->GetIsolate()));
9020 CHECK(line_ends->length());
9021 if (line >= line_ends->length())
9022 return GetSmiValue(line_ends, line_ends->length() - 1);
9023 int line_offset = GetSmiValue(line_ends, line);
9024 if (line == 0) return std::min(column, line_offset);
9025 int prev_line_offset = GetSmiValue(line_ends, line - 1);
9026 return std::min(prev_line_offset + column + 1, line_offset);
9027 }
9028
8953 MaybeLocal<DebugInterface::Script> DebugInterface::Script::Wrap( 9029 MaybeLocal<DebugInterface::Script> DebugInterface::Script::Wrap(
8954 v8::Isolate* v8_isolate, v8::Local<v8::Object> script) { 9030 v8::Isolate* v8_isolate, v8::Local<v8::Object> script) {
8955 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 9031 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
8956 ENTER_V8(isolate); 9032 ENTER_V8(isolate);
8957 i::HandleScope handle_scope(isolate); 9033 i::HandleScope handle_scope(isolate);
8958 i::Handle<i::JSReceiver> script_receiver(Utils::OpenHandle(*script)); 9034 i::Handle<i::JSReceiver> script_receiver(Utils::OpenHandle(*script));
8959 if (!script_receiver->IsJSValue()) return MaybeLocal<Script>(); 9035 if (!script_receiver->IsJSValue()) return MaybeLocal<Script>();
8960 i::Handle<i::Object> script_value( 9036 i::Handle<i::Object> script_value(
8961 i::Handle<i::JSValue>::cast(script_receiver)->value(), isolate); 9037 i::Handle<i::JSValue>::cast(script_receiver)->value(), isolate);
8962 if (!script_value->IsScript()) { 9038 if (!script_value->IsScript()) {
8963 return MaybeLocal<Script>(); 9039 return MaybeLocal<Script>();
8964 } 9040 }
8965 i::Handle<i::Script> script_obj = i::Handle<i::Script>::cast(script_value); 9041 i::Handle<i::Script> script_obj = i::Handle<i::Script>::cast(script_value);
8966 if (script_obj->type() != i::Script::TYPE_NORMAL) return MaybeLocal<Script>(); 9042 if (script_obj->type() != i::Script::TYPE_NORMAL) return MaybeLocal<Script>();
8967 return ToApiHandle<DebugInterface::Script>( 9043 return ToApiHandle<DebugInterface::Script>(
8968 handle_scope.CloseAndEscape(script_obj)); 9044 handle_scope.CloseAndEscape(script_obj));
8969 } 9045 }
8970 9046
9047 DebugInterface::Location::Location(int lineNumber, int columnNumber)
9048 : lineNumber_(lineNumber), columnNumber_(columnNumber) {
9049 CHECK(lineNumber >= 0);
9050 CHECK(columnNumber >= 0);
9051 }
9052
9053 DebugInterface::Location::Location() : lineNumber_(-1), columnNumber_(-1) {}
9054
9055 int DebugInterface::Location::GetLineNumber() const {
9056 CHECK(lineNumber_ >= 0);
9057 return lineNumber_;
9058 }
9059
9060 int DebugInterface::Location::GetColumnNumber() const {
9061 CHECK(columnNumber_ >= 0);
9062 return columnNumber_;
9063 }
9064
9065 bool DebugInterface::Location::IsEmpty() const {
9066 return lineNumber_ == -1 && columnNumber_ == -1;
9067 }
9068
8971 void DebugInterface::GetLoadedScripts( 9069 void DebugInterface::GetLoadedScripts(
8972 v8::Isolate* v8_isolate, 9070 v8::Isolate* v8_isolate,
8973 PersistentValueVector<DebugInterface::Script>& scripts) { 9071 PersistentValueVector<DebugInterface::Script>& scripts) {
8974 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); 9072 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
8975 ENTER_V8(isolate); 9073 ENTER_V8(isolate);
8976 // TODO(kozyatinskiy): remove this GC once tests are dealt with. 9074 // TODO(kozyatinskiy): remove this GC once tests are dealt with.
8977 isolate->heap()->CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask, 9075 isolate->heap()->CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask,
8978 i::GarbageCollectionReason::kDebugger); 9076 i::GarbageCollectionReason::kDebugger);
8979 { 9077 {
8980 i::DisallowHeapAllocation no_gc; 9078 i::DisallowHeapAllocation no_gc;
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
9672 Address callback_address = 9770 Address callback_address =
9673 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 9771 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9674 VMState<EXTERNAL> state(isolate); 9772 VMState<EXTERNAL> state(isolate);
9675 ExternalCallbackScope call_scope(isolate, callback_address); 9773 ExternalCallbackScope call_scope(isolate, callback_address);
9676 callback(info); 9774 callback(info);
9677 } 9775 }
9678 9776
9679 9777
9680 } // namespace internal 9778 } // namespace internal
9681 } // namespace v8 9779 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/debug/debug.h » ('j') | test/inspector/task-runner.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698