V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
debug-frames.cc
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "src/debug/debug-frames.h"
6 
7 #include "src/accessors.h"
8 #include "src/frames-inl.h"
9 #include "src/wasm/wasm-interpreter.h"
10 #include "src/wasm/wasm-objects-inl.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 FrameInspector::FrameInspector(StandardFrame* frame, int inlined_frame_index,
16  Isolate* isolate)
17  : frame_(frame),
18  inlined_frame_index_(inlined_frame_index),
19  isolate_(isolate) {
20  // Extract the relevant information from the frame summary and discard it.
21  FrameSummary summary = FrameSummary::Get(frame, inlined_frame_index);
22 
23  is_constructor_ = summary.is_constructor();
24  source_position_ = summary.SourcePosition();
25  function_name_ = summary.FunctionName();
26  script_ = Handle<Script>::cast(summary.script());
27  receiver_ = summary.receiver();
28 
29  if (summary.IsJavaScript()) {
30  function_ = summary.AsJavaScript().function();
31  }
32 
33  JavaScriptFrame* js_frame =
34  frame->is_java_script() ? javascript_frame() : nullptr;
35  DCHECK(js_frame || frame->is_wasm());
36  has_adapted_arguments_ = js_frame && js_frame->has_adapted_arguments();
37  is_optimized_ = frame_->is_optimized();
38  is_interpreted_ = frame_->is_interpreted();
39 
40  // Calculate the deoptimized frame.
41  if (is_optimized_) {
42  DCHECK_NOT_NULL(js_frame);
43  deoptimized_frame_.reset(Deoptimizer::DebuggerInspectableFrame(
44  js_frame, inlined_frame_index, isolate));
45  } else if (frame_->is_wasm_interpreter_entry()) {
46  wasm_interpreted_frame_ =
47  WasmInterpreterEntryFrame::cast(frame_)
48  ->debug_info()
49  ->GetInterpretedFrame(frame_->fp(), inlined_frame_index);
50  DCHECK(wasm_interpreted_frame_);
51  }
52 }
53 
54 // NOLINTNEXTLINE
55 FrameInspector::~FrameInspector() {
56  // Destructor needs to be defined in the .cc file, because it instantiates
57  // std::unique_ptr destructors but the types are not known in the header.
58 }
59 
60 int FrameInspector::GetParametersCount() {
61  if (is_optimized_) return deoptimized_frame_->parameters_count();
62  if (wasm_interpreted_frame_)
63  return wasm_interpreted_frame_->GetParameterCount();
64  return frame_->ComputeParametersCount();
65 }
66 
67 Handle<Object> FrameInspector::GetParameter(int index) {
68  if (is_optimized_) return deoptimized_frame_->GetParameter(index);
69  // TODO(clemensh): Handle wasm_interpreted_frame_.
70  return handle(frame_->GetParameter(index), isolate_);
71 }
72 
73 Handle<Object> FrameInspector::GetExpression(int index) {
74  return is_optimized_ ? deoptimized_frame_->GetExpression(index)
75  : handle(frame_->GetExpression(index), isolate_);
76 }
77 
78 Handle<Object> FrameInspector::GetContext() {
79  return deoptimized_frame_ ? deoptimized_frame_->GetContext()
80  : handle(frame_->context(), isolate_);
81 }
82 
83 bool FrameInspector::IsWasm() { return frame_->is_wasm(); }
84 
85 bool FrameInspector::IsJavaScript() { return frame_->is_java_script(); }
86 
87 bool FrameInspector::ParameterIsShadowedByContextLocal(
88  Handle<ScopeInfo> info, Handle<String> parameter_name) {
89  VariableMode mode;
90  InitializationFlag init_flag;
91  MaybeAssignedFlag maybe_assigned_flag;
92  return ScopeInfo::ContextSlotIndex(info, parameter_name, &mode, &init_flag,
93  &maybe_assigned_flag) != -1;
94 }
95 } // namespace internal
96 } // namespace v8
Definition: libplatform.h:13