1 | // Copyright 2018 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 | #ifndef V8_OBJECTS_STACK_FRAME_INFO_H_ |
6 | #define V8_OBJECTS_STACK_FRAME_INFO_H_ |
7 | |
8 | #include "src/objects/struct.h" |
9 | |
10 | // Has to be the last include (doesn't have include guards): |
11 | #include "src/objects/object-macros.h" |
12 | |
13 | namespace v8 { |
14 | namespace internal { |
15 | |
16 | class FrameArray; |
17 | |
18 | class StackFrameInfo : public Struct { |
19 | public: |
20 | NEVER_READ_ONLY_SPACE |
21 | DECL_INT_ACCESSORS(line_number) |
22 | DECL_INT_ACCESSORS(column_number) |
23 | DECL_INT_ACCESSORS(script_id) |
24 | DECL_ACCESSORS(script_name, Object) |
25 | DECL_ACCESSORS(script_name_or_source_url, Object) |
26 | DECL_ACCESSORS(function_name, Object) |
27 | DECL_BOOLEAN_ACCESSORS(is_eval) |
28 | DECL_BOOLEAN_ACCESSORS(is_constructor) |
29 | DECL_BOOLEAN_ACCESSORS(is_wasm) |
30 | DECL_INT_ACCESSORS(flag) |
31 | |
32 | DECL_CAST(StackFrameInfo) |
33 | |
34 | // Dispatched behavior. |
35 | DECL_PRINTER(StackFrameInfo) |
36 | DECL_VERIFIER(StackFrameInfo) |
37 | |
38 | DEFINE_FIELD_OFFSET_CONSTANTS(Struct::kHeaderSize, |
39 | TORQUE_GENERATED_STACK_FRAME_INFO_FIELDS) |
40 | |
41 | private: |
42 | // Bit position in the flag, from least significant bit position. |
43 | static const int kIsEvalBit = 0; |
44 | static const int kIsConstructorBit = 1; |
45 | static const int kIsWasmBit = 2; |
46 | |
47 | OBJECT_CONSTRUCTORS(StackFrameInfo, Struct); |
48 | }; |
49 | |
50 | // This class is used to lazily initialize a StackFrameInfo object from |
51 | // a FrameArray plus an index. |
52 | // The first time any of the Get* or Is* methods is called, a |
53 | // StackFrameInfo object is allocated and all necessary information |
54 | // retrieved. |
55 | class StackTraceFrame : public Struct { |
56 | public: |
57 | NEVER_READ_ONLY_SPACE |
58 | DECL_ACCESSORS(frame_array, Object) |
59 | DECL_INT_ACCESSORS(frame_index) |
60 | DECL_ACCESSORS(frame_info, Object) |
61 | DECL_INT_ACCESSORS(id) |
62 | |
63 | DECL_CAST(StackTraceFrame) |
64 | |
65 | // Dispatched behavior. |
66 | DECL_PRINTER(StackTraceFrame) |
67 | DECL_VERIFIER(StackTraceFrame) |
68 | |
69 | // Layout description. |
70 | #define STACK_FRAME_FIELDS(V) \ |
71 | V(kFrameArrayOffset, kTaggedSize) \ |
72 | V(kFrameIndexOffset, kTaggedSize) \ |
73 | V(kFrameInfoOffset, kTaggedSize) \ |
74 | V(kIdOffset, kTaggedSize) \ |
75 | /* Total size. */ \ |
76 | V(kSize, 0) |
77 | |
78 | DEFINE_FIELD_OFFSET_CONSTANTS(Struct::kHeaderSize, STACK_FRAME_FIELDS) |
79 | #undef STACK_FRAME_FIELDS |
80 | |
81 | static int GetLineNumber(Handle<StackTraceFrame> frame); |
82 | static int GetColumnNumber(Handle<StackTraceFrame> frame); |
83 | static int GetScriptId(Handle<StackTraceFrame> frame); |
84 | |
85 | static Handle<Object> GetFileName(Handle<StackTraceFrame> frame); |
86 | static Handle<Object> GetScriptNameOrSourceUrl(Handle<StackTraceFrame> frame); |
87 | static Handle<Object> GetFunctionName(Handle<StackTraceFrame> frame); |
88 | |
89 | static bool IsEval(Handle<StackTraceFrame> frame); |
90 | static bool IsConstructor(Handle<StackTraceFrame> frame); |
91 | static bool IsWasm(Handle<StackTraceFrame> frame); |
92 | |
93 | private: |
94 | OBJECT_CONSTRUCTORS(StackTraceFrame, Struct); |
95 | |
96 | static Handle<StackFrameInfo> GetFrameInfo(Handle<StackTraceFrame> frame); |
97 | static void InitializeFrameInfo(Handle<StackTraceFrame> frame); |
98 | }; |
99 | |
100 | } // namespace internal |
101 | } // namespace v8 |
102 | |
103 | #include "src/objects/object-macros-undef.h" |
104 | |
105 | #endif // V8_OBJECTS_STACK_FRAME_INFO_H_ |
106 | |