5 #include "src/debug/debug-scope-iterator.h" 7 #include "src/api-inl.h" 8 #include "src/debug/debug.h" 9 #include "src/debug/liveedit.h" 10 #include "src/frames-inl.h" 11 #include "src/isolate.h" 12 #include "src/objects/js-generator-inl.h" 13 #include "src/wasm/wasm-objects-inl.h" 17 std::unique_ptr<debug::ScopeIterator> debug::ScopeIterator::CreateForFunction(
19 internal::Handle<internal::JSReceiver> receiver =
20 internal::Handle<internal::JSReceiver>::cast(Utils::OpenHandle(*v8_func));
25 if (!receiver->IsJSFunction())
return nullptr;
27 internal::Handle<internal::JSFunction>
function =
28 internal::Handle<internal::JSFunction>::cast(receiver);
32 if (!function->has_context())
return nullptr;
33 return std::unique_ptr<debug::ScopeIterator>(
new internal::DebugScopeIterator(
34 reinterpret_cast<internal::Isolate*>(v8_isolate),
function));
37 std::unique_ptr<debug::ScopeIterator>
38 debug::ScopeIterator::CreateForGeneratorObject(
40 internal::Handle<internal::Object> generator =
41 Utils::OpenHandle(*v8_generator);
42 DCHECK(generator->IsJSGeneratorObject());
43 return std::unique_ptr<debug::ScopeIterator>(
new internal::DebugScopeIterator(
44 reinterpret_cast<internal::Isolate*>(v8_isolate),
45 internal::Handle<internal::JSGeneratorObject>::cast(generator)));
50 DebugScopeIterator::DebugScopeIterator(Isolate* isolate,
51 FrameInspector* frame_inspector)
52 : iterator_(isolate, frame_inspector) {
53 if (!Done() && ShouldIgnore()) Advance();
56 DebugScopeIterator::DebugScopeIterator(Isolate* isolate,
57 Handle<JSFunction>
function)
58 : iterator_(isolate, function) {
59 if (!Done() && ShouldIgnore()) Advance();
62 DebugScopeIterator::DebugScopeIterator(Isolate* isolate,
63 Handle<JSGeneratorObject> generator)
64 : iterator_(isolate, generator) {
65 if (!Done() && ShouldIgnore()) Advance();
68 bool DebugScopeIterator::Done() {
return iterator_.Done(); }
70 void DebugScopeIterator::Advance() {
73 while (!Done() && ShouldIgnore()) {
78 bool DebugScopeIterator::ShouldIgnore() {
79 if (GetType() == debug::ScopeIterator::ScopeTypeLocal)
return false;
80 return !iterator_.DeclaresLocals(i::ScopeIterator::Mode::ALL);
83 v8::debug::ScopeIterator::ScopeType DebugScopeIterator::GetType() {
85 return static_cast<v8::debug::ScopeIterator::ScopeType
>(iterator_.Type());
90 Handle<JSObject> value = iterator_.ScopeObject(i::ScopeIterator::Mode::ALL);
91 return Utils::ToLocal(value);
94 int DebugScopeIterator::GetScriptId() {
96 return iterator_.GetScript()->id();
101 Handle<Object> name = iterator_.GetFunctionDebugName();
102 return Utils::ToLocal(name);
105 bool DebugScopeIterator::HasLocationInfo() {
106 return iterator_.HasPositionInfo();
109 debug::Location DebugScopeIterator::GetStartLocation() {
111 return ToApiHandle<v8::debug::Script>(iterator_.GetScript())
112 ->GetSourceLocation(iterator_.start_position());
115 debug::Location DebugScopeIterator::GetEndLocation() {
117 return ToApiHandle<v8::debug::Script>(iterator_.GetScript())
118 ->GetSourceLocation(iterator_.end_position());
124 return iterator_.SetVariableValue(Utils::OpenHandle(*name),
125 Utils::OpenHandle(*value));
128 DebugWasmScopeIterator::DebugWasmScopeIterator(Isolate* isolate,
129 StandardFrame* frame,
130 int inlined_frame_index)
133 inlined_frame_index_(inlined_frame_index),
134 type_(debug::ScopeIterator::ScopeTypeGlobal) {}
136 bool DebugWasmScopeIterator::Done() {
137 return type_ != debug::ScopeIterator::ScopeTypeGlobal &&
138 type_ != debug::ScopeIterator::ScopeTypeLocal;
141 void DebugWasmScopeIterator::Advance() {
143 if (type_ == debug::ScopeIterator::ScopeTypeGlobal) {
144 type_ = debug::ScopeIterator::ScopeTypeLocal;
147 type_ = debug::ScopeIterator::ScopeTypeWith;
151 v8::debug::ScopeIterator::ScopeType DebugWasmScopeIterator::GetType() {
158 Handle<WasmDebugInfo> debug_info(
159 WasmInterpreterEntryFrame::cast(frame_)->debug_info(), isolate_);
161 case debug::ScopeIterator::ScopeTypeGlobal:
162 return Utils::ToLocal(WasmDebugInfo::GetGlobalScopeObject(
163 debug_info, frame_->fp(), inlined_frame_index_));
164 case debug::ScopeIterator::ScopeTypeLocal:
165 return Utils::ToLocal(WasmDebugInfo::GetLocalScopeObject(
166 debug_info, frame_->fp(), inlined_frame_index_));
173 int DebugWasmScopeIterator::GetScriptId() {
180 return Utils::ToLocal(isolate_->factory()->empty_string());
183 bool DebugWasmScopeIterator::HasLocationInfo() {
return false; }
185 debug::Location DebugWasmScopeIterator::GetStartLocation() {
187 return debug::Location();
190 debug::Location DebugWasmScopeIterator::GetEndLocation() {
192 return debug::Location();