| 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 8818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8829 Local<Value> value) { | 8829 Local<Value> value) { |
| 8830 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 8830 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 8831 ENTER_V8(isolate); | 8831 ENTER_V8(isolate); |
| 8832 i::Handle<i::Object> val = Utils::OpenHandle(*value); | 8832 i::Handle<i::Object> val = Utils::OpenHandle(*value); |
| 8833 i::Handle<i::JSArray> result; | 8833 i::Handle<i::JSArray> result; |
| 8834 if (!i::Runtime::GetInternalProperties(isolate, val).ToHandle(&result)) | 8834 if (!i::Runtime::GetInternalProperties(isolate, val).ToHandle(&result)) |
| 8835 return MaybeLocal<Array>(); | 8835 return MaybeLocal<Array>(); |
| 8836 return Utils::ToLocal(result); | 8836 return Utils::ToLocal(result); |
| 8837 } | 8837 } |
| 8838 | 8838 |
| 8839 bool DebugInterface::SetDebugEventListener(Isolate* isolate, | 8839 bool debug::DebugInterface::SetDebugEventListener( |
| 8840 DebugInterface::EventCallback that, | 8840 Isolate* isolate, debug::DebugInterface::EventCallback that, |
| 8841 Local<Value> data) { | 8841 Local<Value> data) { |
| 8842 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 8842 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 8843 ENTER_V8(i_isolate); | 8843 ENTER_V8(i_isolate); |
| 8844 i::HandleScope scope(i_isolate); | 8844 i::HandleScope scope(i_isolate); |
| 8845 i::Handle<i::Object> foreign = i_isolate->factory()->undefined_value(); | 8845 i::Handle<i::Object> foreign = i_isolate->factory()->undefined_value(); |
| 8846 if (that != NULL) { | 8846 if (that != NULL) { |
| 8847 foreign = i_isolate->factory()->NewForeign(FUNCTION_ADDR(that)); | 8847 foreign = i_isolate->factory()->NewForeign(FUNCTION_ADDR(that)); |
| 8848 } | 8848 } |
| 8849 i_isolate->debug()->SetEventListener(foreign, Utils::OpenHandle(*data, true)); | 8849 i_isolate->debug()->SetEventListener(foreign, Utils::OpenHandle(*data, true)); |
| 8850 return true; | 8850 return true; |
| 8851 } | 8851 } |
| 8852 | 8852 |
| 8853 Local<Context> DebugInterface::GetDebugContext(Isolate* isolate) { | 8853 Local<Context> debug::DebugInterface::GetDebugContext(Isolate* isolate) { |
| 8854 return Debug::GetDebugContext(isolate); | 8854 return Debug::GetDebugContext(isolate); |
| 8855 } | 8855 } |
| 8856 | 8856 |
| 8857 MaybeLocal<Value> DebugInterface::Call(Local<Context> context, | 8857 MaybeLocal<Value> debug::DebugInterface::Call(Local<Context> context, |
| 8858 v8::Local<v8::Function> fun, | 8858 v8::Local<v8::Function> fun, |
| 8859 v8::Local<v8::Value> data) { | 8859 v8::Local<v8::Value> data) { |
| 8860 return Debug::Call(context, fun, data); | 8860 return Debug::Call(context, fun, data); |
| 8861 } | 8861 } |
| 8862 | 8862 |
| 8863 void DebugInterface::SetLiveEditEnabled(Isolate* isolate, bool enable) { | 8863 void debug::DebugInterface::SetLiveEditEnabled(Isolate* isolate, bool enable) { |
| 8864 Debug::SetLiveEditEnabled(isolate, enable); | 8864 Debug::SetLiveEditEnabled(isolate, enable); |
| 8865 } | 8865 } |
| 8866 | 8866 |
| 8867 void DebugInterface::DebugBreak(Isolate* isolate) { | 8867 void debug::DebugInterface::DebugBreak(Isolate* isolate) { |
| 8868 Debug::DebugBreak(isolate); | 8868 Debug::DebugBreak(isolate); |
| 8869 } | 8869 } |
| 8870 | 8870 |
| 8871 void DebugInterface::CancelDebugBreak(Isolate* isolate) { | 8871 void debug::DebugInterface::CancelDebugBreak(Isolate* isolate) { |
| 8872 Debug::CancelDebugBreak(isolate); | 8872 Debug::CancelDebugBreak(isolate); |
| 8873 } | 8873 } |
| 8874 | 8874 |
| 8875 MaybeLocal<Array> DebugInterface::GetInternalProperties(Isolate* isolate, | 8875 MaybeLocal<Array> debug::DebugInterface::GetInternalProperties( |
| 8876 Local<Value> value) { | 8876 Isolate* isolate, Local<Value> value) { |
| 8877 return Debug::GetInternalProperties(isolate, value); | 8877 return Debug::GetInternalProperties(isolate, value); |
| 8878 } | 8878 } |
| 8879 | 8879 |
| 8880 void DebugInterface::ChangeBreakOnException(Isolate* isolate, | 8880 void debug::DebugInterface::ChangeBreakOnException(Isolate* isolate, |
| 8881 ExceptionBreakState type) { | 8881 ExceptionBreakState type) { |
| 8882 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); | 8882 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 8883 internal_isolate->debug()->ChangeBreakOnException( | 8883 internal_isolate->debug()->ChangeBreakOnException( |
| 8884 i::BreakException, type == BreakOnAnyException); | 8884 i::BreakException, type == BreakOnAnyException); |
| 8885 internal_isolate->debug()->ChangeBreakOnException(i::BreakUncaughtException, | 8885 internal_isolate->debug()->ChangeBreakOnException(i::BreakUncaughtException, |
| 8886 type != NoBreakOnException); | 8886 type != NoBreakOnException); |
| 8887 } | 8887 } |
| 8888 | 8888 |
| 8889 void DebugInterface::PrepareStep(Isolate* v8_isolate, StepAction action) { | 8889 void debug::DebugInterface::PrepareStep(Isolate* v8_isolate, |
| 8890 StepAction action) { |
| 8890 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 8891 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 8891 ENTER_V8(isolate); | 8892 ENTER_V8(isolate); |
| 8892 CHECK(isolate->debug()->CheckExecutionState()); | 8893 CHECK(isolate->debug()->CheckExecutionState()); |
| 8893 // Clear all current stepping setup. | 8894 // Clear all current stepping setup. |
| 8894 isolate->debug()->ClearStepping(); | 8895 isolate->debug()->ClearStepping(); |
| 8895 // Prepare step. | 8896 // Prepare step. |
| 8896 isolate->debug()->PrepareStep(static_cast<i::StepAction>(action)); | 8897 isolate->debug()->PrepareStep(static_cast<i::StepAction>(action)); |
| 8897 } | 8898 } |
| 8898 | 8899 |
| 8899 void DebugInterface::ClearStepping(Isolate* v8_isolate) { | 8900 void debug::DebugInterface::ClearStepping(Isolate* v8_isolate) { |
| 8900 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 8901 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 8901 ENTER_V8(isolate); | 8902 ENTER_V8(isolate); |
| 8902 // Clear all current stepping setup. | 8903 // Clear all current stepping setup. |
| 8903 isolate->debug()->ClearStepping(); | 8904 isolate->debug()->ClearStepping(); |
| 8904 } | 8905 } |
| 8905 | 8906 |
| 8906 v8::Isolate* DebugInterface::Script::GetIsolate() const { | 8907 v8::Isolate* debug::Script::GetIsolate() const { |
| 8907 return reinterpret_cast<v8::Isolate*>(Utils::OpenHandle(this)->GetIsolate()); | 8908 return reinterpret_cast<v8::Isolate*>(Utils::OpenHandle(this)->GetIsolate()); |
| 8908 } | 8909 } |
| 8909 | 8910 |
| 8910 ScriptOriginOptions DebugInterface::Script::OriginOptions() const { | 8911 ScriptOriginOptions debug::Script::OriginOptions() const { |
| 8911 return Utils::OpenHandle(this)->origin_options(); | 8912 return Utils::OpenHandle(this)->origin_options(); |
| 8912 } | 8913 } |
| 8913 | 8914 |
| 8914 bool DebugInterface::Script::WasCompiled() const { | 8915 bool debug::Script::WasCompiled() const { |
| 8915 return Utils::OpenHandle(this)->compilation_state() == | 8916 return Utils::OpenHandle(this)->compilation_state() == |
| 8916 i::Script::COMPILATION_STATE_COMPILED; | 8917 i::Script::COMPILATION_STATE_COMPILED; |
| 8917 } | 8918 } |
| 8918 | 8919 |
| 8919 int DebugInterface::Script::Id() const { return Utils::OpenHandle(this)->id(); } | 8920 int debug::Script::Id() const { return Utils::OpenHandle(this)->id(); } |
| 8920 | 8921 |
| 8921 int DebugInterface::Script::LineOffset() const { | 8922 int debug::Script::LineOffset() const { |
| 8922 return Utils::OpenHandle(this)->line_offset(); | 8923 return Utils::OpenHandle(this)->line_offset(); |
| 8923 } | 8924 } |
| 8924 | 8925 |
| 8925 int DebugInterface::Script::ColumnOffset() const { | 8926 int debug::Script::ColumnOffset() const { |
| 8926 return Utils::OpenHandle(this)->column_offset(); | 8927 return Utils::OpenHandle(this)->column_offset(); |
| 8927 } | 8928 } |
| 8928 | 8929 |
| 8929 std::vector<int> DebugInterface::Script::LineEnds() const { | 8930 std::vector<int> debug::Script::LineEnds() const { |
| 8930 i::Handle<i::Script> script = Utils::OpenHandle(this); | 8931 i::Handle<i::Script> script = Utils::OpenHandle(this); |
| 8931 if (script->type() == i::Script::TYPE_WASM) return std::vector<int>(); | 8932 if (script->type() == i::Script::TYPE_WASM) return std::vector<int>(); |
| 8932 i::Isolate* isolate = script->GetIsolate(); | 8933 i::Isolate* isolate = script->GetIsolate(); |
| 8933 i::HandleScope scope(isolate); | 8934 i::HandleScope scope(isolate); |
| 8934 i::Script::InitLineEnds(script); | 8935 i::Script::InitLineEnds(script); |
| 8935 CHECK(script->line_ends()->IsFixedArray()); | 8936 CHECK(script->line_ends()->IsFixedArray()); |
| 8936 i::Handle<i::FixedArray> line_ends(i::FixedArray::cast(script->line_ends())); | 8937 i::Handle<i::FixedArray> line_ends(i::FixedArray::cast(script->line_ends())); |
| 8937 std::vector<int> result(line_ends->length()); | 8938 std::vector<int> result(line_ends->length()); |
| 8938 for (int i = 0; i < line_ends->length(); ++i) { | 8939 for (int i = 0; i < line_ends->length(); ++i) { |
| 8939 i::Smi* line_end = i::Smi::cast(line_ends->get(i)); | 8940 i::Smi* line_end = i::Smi::cast(line_ends->get(i)); |
| 8940 result[i] = line_end->value(); | 8941 result[i] = line_end->value(); |
| 8941 } | 8942 } |
| 8942 return result; | 8943 return result; |
| 8943 } | 8944 } |
| 8944 | 8945 |
| 8945 MaybeLocal<String> DebugInterface::Script::Name() const { | 8946 MaybeLocal<String> debug::Script::Name() const { |
| 8946 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 8947 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 8947 i::HandleScope handle_scope(isolate); | 8948 i::HandleScope handle_scope(isolate); |
| 8948 i::Handle<i::Script> script = Utils::OpenHandle(this); | 8949 i::Handle<i::Script> script = Utils::OpenHandle(this); |
| 8949 i::Handle<i::Object> value(script->name(), isolate); | 8950 i::Handle<i::Object> value(script->name(), isolate); |
| 8950 if (!value->IsString()) return MaybeLocal<String>(); | 8951 if (!value->IsString()) return MaybeLocal<String>(); |
| 8951 return Utils::ToLocal( | 8952 return Utils::ToLocal( |
| 8952 handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value))); | 8953 handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value))); |
| 8953 } | 8954 } |
| 8954 | 8955 |
| 8955 MaybeLocal<String> DebugInterface::Script::SourceURL() const { | 8956 MaybeLocal<String> debug::Script::SourceURL() const { |
| 8956 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 8957 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 8957 i::HandleScope handle_scope(isolate); | 8958 i::HandleScope handle_scope(isolate); |
| 8958 i::Handle<i::Script> script = Utils::OpenHandle(this); | 8959 i::Handle<i::Script> script = Utils::OpenHandle(this); |
| 8959 i::Handle<i::Object> value(script->source_url(), isolate); | 8960 i::Handle<i::Object> value(script->source_url(), isolate); |
| 8960 if (!value->IsString()) return MaybeLocal<String>(); | 8961 if (!value->IsString()) return MaybeLocal<String>(); |
| 8961 return Utils::ToLocal( | 8962 return Utils::ToLocal( |
| 8962 handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value))); | 8963 handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value))); |
| 8963 } | 8964 } |
| 8964 | 8965 |
| 8965 MaybeLocal<String> DebugInterface::Script::SourceMappingURL() const { | 8966 MaybeLocal<String> debug::Script::SourceMappingURL() const { |
| 8966 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 8967 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 8967 i::HandleScope handle_scope(isolate); | 8968 i::HandleScope handle_scope(isolate); |
| 8968 i::Handle<i::Script> script = Utils::OpenHandle(this); | 8969 i::Handle<i::Script> script = Utils::OpenHandle(this); |
| 8969 i::Handle<i::Object> value(script->source_mapping_url(), isolate); | 8970 i::Handle<i::Object> value(script->source_mapping_url(), isolate); |
| 8970 if (!value->IsString()) return MaybeLocal<String>(); | 8971 if (!value->IsString()) return MaybeLocal<String>(); |
| 8971 return Utils::ToLocal( | 8972 return Utils::ToLocal( |
| 8972 handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value))); | 8973 handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value))); |
| 8973 } | 8974 } |
| 8974 | 8975 |
| 8975 MaybeLocal<String> DebugInterface::Script::ContextData() const { | 8976 MaybeLocal<String> debug::Script::ContextData() const { |
| 8976 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 8977 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 8977 i::HandleScope handle_scope(isolate); | 8978 i::HandleScope handle_scope(isolate); |
| 8978 i::Handle<i::Script> script = Utils::OpenHandle(this); | 8979 i::Handle<i::Script> script = Utils::OpenHandle(this); |
| 8979 i::Handle<i::Object> value(script->context_data(), isolate); | 8980 i::Handle<i::Object> value(script->context_data(), isolate); |
| 8980 if (!value->IsString()) return MaybeLocal<String>(); | 8981 if (!value->IsString()) return MaybeLocal<String>(); |
| 8981 return Utils::ToLocal( | 8982 return Utils::ToLocal( |
| 8982 handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value))); | 8983 handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value))); |
| 8983 } | 8984 } |
| 8984 | 8985 |
| 8985 MaybeLocal<String> DebugInterface::Script::Source() const { | 8986 MaybeLocal<String> debug::Script::Source() const { |
| 8986 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 8987 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 8987 i::HandleScope handle_scope(isolate); | 8988 i::HandleScope handle_scope(isolate); |
| 8988 i::Handle<i::Script> script = Utils::OpenHandle(this); | 8989 i::Handle<i::Script> script = Utils::OpenHandle(this); |
| 8989 i::Handle<i::Object> value(script->source(), isolate); | 8990 i::Handle<i::Object> value(script->source(), isolate); |
| 8990 if (!value->IsString()) return MaybeLocal<String>(); | 8991 if (!value->IsString()) return MaybeLocal<String>(); |
| 8991 return Utils::ToLocal( | 8992 return Utils::ToLocal( |
| 8992 handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value))); | 8993 handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value))); |
| 8993 } | 8994 } |
| 8994 | 8995 |
| 8995 bool DebugInterface::Script::IsWasm() const { | 8996 bool debug::Script::IsWasm() const { |
| 8996 return Utils::OpenHandle(this)->type() == i::Script::TYPE_WASM; | 8997 return Utils::OpenHandle(this)->type() == i::Script::TYPE_WASM; |
| 8997 } | 8998 } |
| 8998 | 8999 |
| 8999 namespace { | 9000 namespace { |
| 9000 int GetSmiValue(i::Handle<i::FixedArray> array, int index) { | 9001 int GetSmiValue(i::Handle<i::FixedArray> array, int index) { |
| 9001 return i::Smi::cast(array->get(index))->value(); | 9002 return i::Smi::cast(array->get(index))->value(); |
| 9002 } | 9003 } |
| 9003 } // namespace | 9004 } // namespace |
| 9004 | 9005 |
| 9005 bool DebugInterface::Script::GetPossibleBreakpoints( | 9006 bool debug::Script::GetPossibleBreakpoints( |
| 9006 const debug::Location& start, const debug::Location& end, | 9007 const debug::Location& start, const debug::Location& end, |
| 9007 std::vector<debug::Location>* locations) const { | 9008 std::vector<debug::Location>* locations) const { |
| 9008 CHECK(!start.IsEmpty()); | 9009 CHECK(!start.IsEmpty()); |
| 9009 i::Handle<i::Script> script = Utils::OpenHandle(this); | 9010 i::Handle<i::Script> script = Utils::OpenHandle(this); |
| 9010 if (script->type() == i::Script::TYPE_WASM) { | 9011 if (script->type() == i::Script::TYPE_WASM) { |
| 9011 // TODO(clemensh): Return the proper thing once we support wasm breakpoints. | 9012 // TODO(clemensh): Return the proper thing once we support wasm breakpoints. |
| 9012 return false; | 9013 return false; |
| 9013 } | 9014 } |
| 9014 | 9015 |
| 9015 i::Script::InitLineEnds(script); | 9016 i::Script::InitLineEnds(script); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9047 line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1; | 9048 line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1; |
| 9048 } | 9049 } |
| 9049 locations->push_back(debug::Location( | 9050 locations->push_back(debug::Location( |
| 9050 current_line_end_index + script->line_offset(), | 9051 current_line_end_index + script->line_offset(), |
| 9051 offset - line_offset + | 9052 offset - line_offset + |
| 9052 (current_line_end_index == 0 ? script->column_offset() : 0))); | 9053 (current_line_end_index == 0 ? script->column_offset() : 0))); |
| 9053 } | 9054 } |
| 9054 return true; | 9055 return true; |
| 9055 } | 9056 } |
| 9056 | 9057 |
| 9057 int DebugInterface::Script::GetSourcePosition( | 9058 int debug::Script::GetSourcePosition(const debug::Location& location) const { |
| 9058 const debug::Location& location) const { | |
| 9059 i::Handle<i::Script> script = Utils::OpenHandle(this); | 9059 i::Handle<i::Script> script = Utils::OpenHandle(this); |
| 9060 if (script->type() == i::Script::TYPE_WASM) { | 9060 if (script->type() == i::Script::TYPE_WASM) { |
| 9061 // TODO(clemensh): Return the proper thing for wasm. | 9061 // TODO(clemensh): Return the proper thing for wasm. |
| 9062 return 0; | 9062 return 0; |
| 9063 } | 9063 } |
| 9064 | 9064 |
| 9065 int line = std::max(location.GetLineNumber() - script->line_offset(), 0); | 9065 int line = std::max(location.GetLineNumber() - script->line_offset(), 0); |
| 9066 int column = location.GetColumnNumber(); | 9066 int column = location.GetColumnNumber(); |
| 9067 if (line == 0) { | 9067 if (line == 0) { |
| 9068 column = std::max(0, column - script->column_offset()); | 9068 column = std::max(0, column - script->column_offset()); |
| 9069 } | 9069 } |
| 9070 | 9070 |
| 9071 i::Script::InitLineEnds(script); | 9071 i::Script::InitLineEnds(script); |
| 9072 CHECK(script->line_ends()->IsFixedArray()); | 9072 CHECK(script->line_ends()->IsFixedArray()); |
| 9073 i::Handle<i::FixedArray> line_ends = i::Handle<i::FixedArray>::cast( | 9073 i::Handle<i::FixedArray> line_ends = i::Handle<i::FixedArray>::cast( |
| 9074 i::handle(script->line_ends(), script->GetIsolate())); | 9074 i::handle(script->line_ends(), script->GetIsolate())); |
| 9075 CHECK(line_ends->length()); | 9075 CHECK(line_ends->length()); |
| 9076 if (line >= line_ends->length()) | 9076 if (line >= line_ends->length()) |
| 9077 return GetSmiValue(line_ends, line_ends->length() - 1); | 9077 return GetSmiValue(line_ends, line_ends->length() - 1); |
| 9078 int line_offset = GetSmiValue(line_ends, line); | 9078 int line_offset = GetSmiValue(line_ends, line); |
| 9079 if (line == 0) return std::min(column, line_offset); | 9079 if (line == 0) return std::min(column, line_offset); |
| 9080 int prev_line_offset = GetSmiValue(line_ends, line - 1); | 9080 int prev_line_offset = GetSmiValue(line_ends, line - 1); |
| 9081 return std::min(prev_line_offset + column + 1, line_offset); | 9081 return std::min(prev_line_offset + column + 1, line_offset); |
| 9082 } | 9082 } |
| 9083 | 9083 |
| 9084 MaybeLocal<DebugInterface::Script> DebugInterface::Script::Wrap( | 9084 MaybeLocal<debug::Script> debug::Script::Wrap(v8::Isolate* v8_isolate, |
| 9085 v8::Isolate* v8_isolate, v8::Local<v8::Object> script) { | 9085 v8::Local<v8::Object> script) { |
| 9086 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 9086 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 9087 ENTER_V8(isolate); | 9087 ENTER_V8(isolate); |
| 9088 i::HandleScope handle_scope(isolate); | 9088 i::HandleScope handle_scope(isolate); |
| 9089 i::Handle<i::JSReceiver> script_receiver(Utils::OpenHandle(*script)); | 9089 i::Handle<i::JSReceiver> script_receiver(Utils::OpenHandle(*script)); |
| 9090 if (!script_receiver->IsJSValue()) return MaybeLocal<Script>(); | 9090 if (!script_receiver->IsJSValue()) return MaybeLocal<Script>(); |
| 9091 i::Handle<i::Object> script_value( | 9091 i::Handle<i::Object> script_value( |
| 9092 i::Handle<i::JSValue>::cast(script_receiver)->value(), isolate); | 9092 i::Handle<i::JSValue>::cast(script_receiver)->value(), isolate); |
| 9093 if (!script_value->IsScript()) { | 9093 if (!script_value->IsScript()) { |
| 9094 return MaybeLocal<Script>(); | 9094 return MaybeLocal<Script>(); |
| 9095 } | 9095 } |
| 9096 i::Handle<i::Script> script_obj = i::Handle<i::Script>::cast(script_value); | 9096 i::Handle<i::Script> script_obj = i::Handle<i::Script>::cast(script_value); |
| 9097 if (script_obj->type() != i::Script::TYPE_NORMAL && | 9097 if (script_obj->type() != i::Script::TYPE_NORMAL && |
| 9098 script_obj->type() != i::Script::TYPE_WASM) { | 9098 script_obj->type() != i::Script::TYPE_WASM) { |
| 9099 return MaybeLocal<Script>(); | 9099 return MaybeLocal<Script>(); |
| 9100 } | 9100 } |
| 9101 return ToApiHandle<DebugInterface::Script>( | 9101 return ToApiHandle<debug::Script>(handle_scope.CloseAndEscape(script_obj)); |
| 9102 handle_scope.CloseAndEscape(script_obj)); | |
| 9103 } | 9102 } |
| 9104 | 9103 |
| 9105 debug::Location::Location(int line_number, int column_number) | 9104 debug::Location::Location(int line_number, int column_number) |
| 9106 : line_number_(line_number), column_number_(column_number) { | 9105 : line_number_(line_number), column_number_(column_number) { |
| 9107 CHECK(line_number >= 0); | 9106 CHECK(line_number >= 0); |
| 9108 CHECK(column_number >= 0); | 9107 CHECK(column_number >= 0); |
| 9109 } | 9108 } |
| 9110 | 9109 |
| 9111 debug::Location::Location() : line_number_(-1), column_number_(-1) {} | 9110 debug::Location::Location() : line_number_(-1), column_number_(-1) {} |
| 9112 | 9111 |
| 9113 int debug::Location::GetLineNumber() const { | 9112 int debug::Location::GetLineNumber() const { |
| 9114 CHECK(line_number_ >= 0); | 9113 CHECK(line_number_ >= 0); |
| 9115 return line_number_; | 9114 return line_number_; |
| 9116 } | 9115 } |
| 9117 | 9116 |
| 9118 int debug::Location::GetColumnNumber() const { | 9117 int debug::Location::GetColumnNumber() const { |
| 9119 CHECK(column_number_ >= 0); | 9118 CHECK(column_number_ >= 0); |
| 9120 return column_number_; | 9119 return column_number_; |
| 9121 } | 9120 } |
| 9122 | 9121 |
| 9123 bool debug::Location::IsEmpty() const { | 9122 bool debug::Location::IsEmpty() const { |
| 9124 return line_number_ == -1 && column_number_ == -1; | 9123 return line_number_ == -1 && column_number_ == -1; |
| 9125 } | 9124 } |
| 9126 | 9125 |
| 9127 void DebugInterface::GetLoadedScripts( | 9126 void debug::DebugInterface::GetLoadedScripts( |
| 9128 v8::Isolate* v8_isolate, | 9127 v8::Isolate* v8_isolate, PersistentValueVector<debug::Script>& scripts) { |
| 9129 PersistentValueVector<DebugInterface::Script>& scripts) { | |
| 9130 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 9128 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 9131 ENTER_V8(isolate); | 9129 ENTER_V8(isolate); |
| 9132 // TODO(kozyatinskiy): remove this GC once tests are dealt with. | 9130 // TODO(kozyatinskiy): remove this GC once tests are dealt with. |
| 9133 isolate->heap()->CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask, | 9131 isolate->heap()->CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask, |
| 9134 i::GarbageCollectionReason::kDebugger); | 9132 i::GarbageCollectionReason::kDebugger); |
| 9135 { | 9133 { |
| 9136 i::DisallowHeapAllocation no_gc; | 9134 i::DisallowHeapAllocation no_gc; |
| 9137 i::Script::Iterator iterator(isolate); | 9135 i::Script::Iterator iterator(isolate); |
| 9138 i::Script* script; | 9136 i::Script* script; |
| 9139 while ((script = iterator.Next())) { | 9137 while ((script = iterator.Next())) { |
| 9140 if (script->type() != i::Script::TYPE_NORMAL) continue; | 9138 if (script->type() != i::Script::TYPE_NORMAL) continue; |
| 9141 if (script->HasValidSource()) { | 9139 if (script->HasValidSource()) { |
| 9142 i::HandleScope handle_scope(isolate); | 9140 i::HandleScope handle_scope(isolate); |
| 9143 i::Handle<i::Script> script_handle(script, isolate); | 9141 i::Handle<i::Script> script_handle(script, isolate); |
| 9144 scripts.Append(ToApiHandle<Script>(script_handle)); | 9142 scripts.Append(ToApiHandle<Script>(script_handle)); |
| 9145 } | 9143 } |
| 9146 } | 9144 } |
| 9147 } | 9145 } |
| 9148 } | 9146 } |
| 9149 | 9147 |
| 9150 debug::WasmDisassembly DebugInterface::DisassembleWasmFunction( | 9148 debug::WasmDisassembly debug::DebugInterface::DisassembleWasmFunction( |
| 9151 Isolate* v8_isolate, Local<Object> v8_script, int function_index) { | 9149 Isolate* v8_isolate, Local<Object> v8_script, int function_index) { |
| 9152 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 9150 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 9153 if (v8_script.IsEmpty()) return {}; | 9151 if (v8_script.IsEmpty()) return {}; |
| 9154 i::Handle<i::Object> script_wrapper = Utils::OpenHandle(*v8_script); | 9152 i::Handle<i::Object> script_wrapper = Utils::OpenHandle(*v8_script); |
| 9155 if (!script_wrapper->IsJSValue()) return {}; | 9153 if (!script_wrapper->IsJSValue()) return {}; |
| 9156 i::Handle<i::Object> script_obj( | 9154 i::Handle<i::Object> script_obj( |
| 9157 i::Handle<i::JSValue>::cast(script_wrapper)->value(), isolate); | 9155 i::Handle<i::JSValue>::cast(script_wrapper)->value(), isolate); |
| 9158 if (!script_obj->IsScript()) return {}; | 9156 if (!script_obj->IsScript()) return {}; |
| 9159 i::Handle<i::Script> script = i::Handle<i::Script>::cast(script_obj); | 9157 i::Handle<i::Script> script = i::Handle<i::Script>::cast(script_obj); |
| 9160 if (script->type() != i::Script::TYPE_WASM) return {}; | 9158 if (script->type() != i::Script::TYPE_WASM) return {}; |
| 9161 i::Handle<i::WasmCompiledModule> compiled_module( | 9159 i::Handle<i::WasmCompiledModule> compiled_module( |
| 9162 i::WasmCompiledModule::cast(script->wasm_compiled_module()), isolate); | 9160 i::WasmCompiledModule::cast(script->wasm_compiled_module()), isolate); |
| 9163 return compiled_module->DisassembleFunction(function_index); | 9161 return compiled_module->DisassembleFunction(function_index); |
| 9164 } | 9162 } |
| 9165 | 9163 |
| 9166 MaybeLocal<UnboundScript> DebugInterface::CompileInspectorScript( | 9164 MaybeLocal<UnboundScript> debug::DebugInterface::CompileInspectorScript( |
| 9167 Isolate* v8_isolate, Local<String> source) { | 9165 Isolate* v8_isolate, Local<String> source) { |
| 9168 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 9166 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 9169 PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(isolate, UnboundScript); | 9167 PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(isolate, UnboundScript); |
| 9170 i::ScriptData* script_data = NULL; | 9168 i::ScriptData* script_data = NULL; |
| 9171 i::Handle<i::String> str = Utils::OpenHandle(*source); | 9169 i::Handle<i::String> str = Utils::OpenHandle(*source); |
| 9172 i::Handle<i::SharedFunctionInfo> result; | 9170 i::Handle<i::SharedFunctionInfo> result; |
| 9173 { | 9171 { |
| 9174 ScriptOriginOptions origin_options; | 9172 ScriptOriginOptions origin_options; |
| 9175 result = i::Compiler::GetSharedFunctionInfoForScript( | 9173 result = i::Compiler::GetSharedFunctionInfoForScript( |
| 9176 str, i::Handle<i::Object>(), 0, 0, origin_options, | 9174 str, i::Handle<i::Object>(), 0, 0, origin_options, |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9863 Address callback_address = | 9861 Address callback_address = |
| 9864 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9862 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 9865 VMState<EXTERNAL> state(isolate); | 9863 VMState<EXTERNAL> state(isolate); |
| 9866 ExternalCallbackScope call_scope(isolate, callback_address); | 9864 ExternalCallbackScope call_scope(isolate, callback_address); |
| 9867 callback(info); | 9865 callback(info); |
| 9868 } | 9866 } |
| 9869 | 9867 |
| 9870 | 9868 |
| 9871 } // namespace internal | 9869 } // namespace internal |
| 9872 } // namespace v8 | 9870 } // namespace v8 |
| OLD | NEW |