OLD | NEW |
---|---|
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 Loading... | |
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 int start_line, int start_column, int end_line, int end_column, | |
8931 std::vector<int>& positions) const { | |
Yang
2016/11/03 08:03:26
Can we use std::pair<int, int> or a struct to wrap
kozy
2016/11/03 17:26:44
Replaced with Location object. I can convert it in
| |
8932 i::Handle<i::Script> script = Utils::OpenHandle(this); | |
8933 int start_offset = GetSourcePosition(start_line, start_column); | |
8934 int end_offset; | |
8935 if (end_line == -1 || end_column == -1) | |
8936 end_offset = GetSourcePosition(static_cast<int>(LineEnds().size()), 0); | |
8937 else | |
8938 end_offset = GetSourcePosition(end_line, end_column); | |
8939 if (start_offset >= end_offset) return true; | |
8940 | |
8941 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
8942 std::vector<int> offsets; | |
8943 if (!isolate->debug()->GetPossibleBreakpoints(script, start_offset, | |
8944 end_offset, offsets)) | |
8945 return false; | |
8946 std::set<int> unique_offsets; | |
8947 for (size_t i = 0; i < offsets.size(); ++i) unique_offsets.insert(offsets[i]); | |
8948 | |
8949 int current_line_end_index = 0; | |
8950 std::vector<int> line_endings = LineEnds(); | |
8951 for (const auto& it : unique_offsets) { | |
8952 int offset = it; | |
8953 while (offset > line_endings[current_line_end_index] && | |
8954 current_line_end_index < line_endings.size()) | |
8955 ++current_line_end_index; | |
8956 CHECK(current_line_end_index < line_endings.size()); | |
8957 positions.push_back(current_line_end_index); | |
8958 positions.push_back(offset - | |
8959 (current_line_end_index > 0 | |
8960 ? (line_endings[current_line_end_index - 1] + 1) | |
8961 : 0)); | |
8962 } | |
8963 return true; | |
8964 } | |
8965 | |
8966 int DebugInterface::Script::GetSourcePosition(int line, int column) const { | |
8967 i::Handle<i::Script> script = Utils::OpenHandle(this); | |
8968 std::vector<int> line_endings = LineEnds(); | |
8969 if (line == 0) return std::min(column, line_endings[line]); | |
8970 if (line >= line_endings.size()) return line_endings.back(); | |
8971 return std::min(line_endings[line - 1] + column + 1, line_endings[line]); | |
8972 } | |
8973 | |
8929 MaybeLocal<DebugInterface::Script> DebugInterface::Script::Wrap( | 8974 MaybeLocal<DebugInterface::Script> DebugInterface::Script::Wrap( |
8930 v8::Isolate* v8_isolate, v8::Local<v8::Object> script) { | 8975 v8::Isolate* v8_isolate, v8::Local<v8::Object> script) { |
8931 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 8976 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
8932 ENTER_V8(isolate); | 8977 ENTER_V8(isolate); |
8933 i::HandleScope handle_scope(isolate); | 8978 i::HandleScope handle_scope(isolate); |
8934 i::Handle<i::JSReceiver> script_receiver(Utils::OpenHandle(*script)); | 8979 i::Handle<i::JSReceiver> script_receiver(Utils::OpenHandle(*script)); |
8935 if (!script_receiver->IsJSValue()) return MaybeLocal<Script>(); | 8980 if (!script_receiver->IsJSValue()) return MaybeLocal<Script>(); |
8936 i::Handle<i::Object> script_value( | 8981 i::Handle<i::Object> script_value( |
8937 i::Handle<i::JSValue>::cast(script_receiver)->value(), isolate); | 8982 i::Handle<i::JSValue>::cast(script_receiver)->value(), isolate); |
8938 if (!script_value->IsScript()) { | 8983 if (!script_value->IsScript()) { |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9640 Address callback_address = | 9685 Address callback_address = |
9641 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9686 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9642 VMState<EXTERNAL> state(isolate); | 9687 VMState<EXTERNAL> state(isolate); |
9643 ExternalCallbackScope call_scope(isolate, callback_address); | 9688 ExternalCallbackScope call_scope(isolate, callback_address); |
9644 callback(info); | 9689 callback(info); |
9645 } | 9690 } |
9646 | 9691 |
9647 | 9692 |
9648 } // namespace internal | 9693 } // namespace internal |
9649 } // namespace v8 | 9694 } // namespace v8 |
OLD | NEW |