OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 // The infrastructure used for (localized) message reporting in V8. | 5 // The infrastructure used for (localized) message reporting in V8. |
6 // | 6 // |
7 // Note: there's a big unresolved issue about ownership of the data | 7 // Note: there's a big unresolved issue about ownership of the data |
8 // structures used by this framework. | 8 // structures used by this framework. |
9 | 9 |
10 #ifndef V8_MESSAGES_H_ | 10 #ifndef V8_MESSAGES_H_ |
11 #define V8_MESSAGES_H_ | 11 #define V8_MESSAGES_H_ |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 #include "src/handles.h" | 15 #include "src/handles.h" |
16 #include "src/list.h" | 16 #include "src/list.h" |
17 | 17 |
18 namespace v8 { | 18 namespace v8 { |
19 namespace internal { | 19 namespace internal { |
20 | 20 |
21 // Forward declarations. | 21 // Forward declarations. |
| 22 class AbstractCode; |
| 23 class FrameArray; |
22 class JSMessageObject; | 24 class JSMessageObject; |
23 class LookupIterator; | 25 class LookupIterator; |
24 class SourceInfo; | 26 class SourceInfo; |
25 | 27 |
26 class MessageLocation { | 28 class MessageLocation { |
27 public: | 29 public: |
28 MessageLocation(Handle<Script> script, int start_pos, int end_pos); | 30 MessageLocation(Handle<Script> script, int start_pos, int end_pos); |
29 MessageLocation(Handle<Script> script, int start_pos, int end_pos, | 31 MessageLocation(Handle<Script> script, int start_pos, int end_pos, |
30 Handle<JSFunction> function); | 32 Handle<JSFunction> function); |
31 MessageLocation(); | 33 MessageLocation(); |
32 | 34 |
33 Handle<Script> script() const { return script_; } | 35 Handle<Script> script() const { return script_; } |
34 int start_pos() const { return start_pos_; } | 36 int start_pos() const { return start_pos_; } |
35 int end_pos() const { return end_pos_; } | 37 int end_pos() const { return end_pos_; } |
36 Handle<JSFunction> function() const { return function_; } | 38 Handle<JSFunction> function() const { return function_; } |
37 | 39 |
38 private: | 40 private: |
39 Handle<Script> script_; | 41 Handle<Script> script_; |
40 int start_pos_; | 42 int start_pos_; |
41 int end_pos_; | 43 int end_pos_; |
42 Handle<JSFunction> function_; | 44 Handle<JSFunction> function_; |
43 }; | 45 }; |
44 | 46 |
| 47 class StackFrameBase { |
| 48 public: |
| 49 virtual ~StackFrameBase() {} |
45 | 50 |
46 class CallSite { | 51 virtual Handle<Object> GetReceiver() const = 0; |
| 52 virtual Handle<Object> GetFunction() const = 0; |
| 53 |
| 54 virtual Handle<Object> GetFileName() = 0; |
| 55 virtual Handle<Object> GetFunctionName() = 0; |
| 56 virtual Handle<Object> GetScriptNameOrSourceUrl() = 0; |
| 57 virtual Handle<Object> GetMethodName() = 0; |
| 58 virtual Handle<Object> GetTypeName() = 0; |
| 59 virtual Handle<Object> GetEvalOrigin() = 0; |
| 60 |
| 61 virtual int GetPosition() const = 0; |
| 62 // Return 1-based line number, including line offset. |
| 63 virtual int GetLineNumber() = 0; |
| 64 // Return 1-based column number, including column offset if first line. |
| 65 virtual int GetColumnNumber() = 0; |
| 66 |
| 67 virtual bool IsNative() = 0; |
| 68 virtual bool IsToplevel() = 0; |
| 69 virtual bool IsEval() = 0; |
| 70 virtual bool IsConstructor() = 0; |
| 71 virtual bool IsStrict() const = 0; |
| 72 |
| 73 virtual MaybeHandle<String> ToString() = 0; |
| 74 }; |
| 75 |
| 76 class JSStackFrame : public StackFrameBase { |
47 public: | 77 public: |
48 CallSite(Isolate* isolate, Handle<JSObject> call_site_obj); | 78 JSStackFrame(Isolate* isolate, Handle<Object> receiver, |
| 79 Handle<JSFunction> function, Handle<AbstractCode> code, |
| 80 int offset); |
| 81 virtual ~JSStackFrame() {} |
49 | 82 |
50 Handle<Object> GetFileName(); | 83 Handle<Object> GetReceiver() const override { return receiver_; } |
51 Handle<Object> GetFunctionName(); | 84 Handle<Object> GetFunction() const override; |
52 Handle<Object> GetScriptNameOrSourceUrl(); | |
53 Handle<Object> GetMethodName(); | |
54 Handle<Object> GetTypeName(); | |
55 Handle<Object> GetEvalOrigin(); | |
56 // Return 1-based line number, including line offset. | |
57 int GetLineNumber(); | |
58 // Return 1-based column number, including column offset if first line. | |
59 int GetColumnNumber(); | |
60 bool IsNative(); | |
61 bool IsToplevel(); | |
62 bool IsEval(); | |
63 bool IsConstructor(); | |
64 | 85 |
65 bool IsJavaScript() { return !fun_.is_null(); } | 86 Handle<Object> GetFileName() override; |
66 bool IsWasm() { return !wasm_obj_.is_null(); } | 87 Handle<Object> GetFunctionName() override; |
| 88 Handle<Object> GetScriptNameOrSourceUrl() override; |
| 89 Handle<Object> GetMethodName() override; |
| 90 Handle<Object> GetTypeName() override; |
| 91 Handle<Object> GetEvalOrigin() override; |
67 | 92 |
68 int wasm_func_index() const { return wasm_func_index_; } | 93 int GetPosition() const override; |
| 94 int GetLineNumber() override; |
| 95 int GetColumnNumber() override; |
| 96 |
| 97 bool IsNative() override; |
| 98 bool IsToplevel() override; |
| 99 bool IsEval() override; |
| 100 bool IsConstructor() override; |
| 101 bool IsStrict() const override { return is_strict_; } |
| 102 |
| 103 MaybeHandle<String> ToString() override; |
| 104 |
| 105 private: |
| 106 JSStackFrame(); |
| 107 void FromFrameArray(Isolate* isolate, Handle<FrameArray> array, int frame_ix); |
| 108 |
| 109 bool HasScript() const; |
| 110 Handle<Script> GetScript() const; |
| 111 |
| 112 Isolate* isolate_; |
| 113 |
| 114 Handle<Object> receiver_; |
| 115 Handle<JSFunction> function_; |
| 116 Handle<AbstractCode> code_; |
| 117 int offset_; |
| 118 |
| 119 bool force_constructor_; |
| 120 bool is_strict_; |
| 121 |
| 122 friend class FrameArrayIterator; |
| 123 }; |
| 124 |
| 125 class WasmStackFrame : public StackFrameBase { |
| 126 public: |
| 127 virtual ~WasmStackFrame() {} |
| 128 |
| 129 Handle<Object> GetReceiver() const override { return wasm_obj_; } |
| 130 Handle<Object> GetFunction() const override; |
| 131 |
| 132 Handle<Object> GetFileName() override { return Null(); } |
| 133 Handle<Object> GetFunctionName() override; |
| 134 Handle<Object> GetScriptNameOrSourceUrl() override { return Null(); } |
| 135 Handle<Object> GetMethodName() override { return Null(); } |
| 136 Handle<Object> GetTypeName() override { return Null(); } |
| 137 Handle<Object> GetEvalOrigin() override { return Null(); } |
| 138 |
| 139 int GetPosition() const override; |
| 140 int GetLineNumber() override { return wasm_func_index_; } |
| 141 int GetColumnNumber() override { return -1; } |
| 142 |
| 143 bool IsNative() override { return false; } |
| 144 bool IsToplevel() override { return false; } |
| 145 bool IsEval() override { return false; } |
| 146 bool IsConstructor() override { return false; } |
| 147 bool IsStrict() const override { return false; } |
| 148 |
| 149 MaybeHandle<String> ToString() override; |
| 150 |
| 151 private: |
| 152 void FromFrameArray(Isolate* isolate, Handle<FrameArray> array, int frame_ix); |
| 153 Handle<Object> Null() const; |
| 154 |
| 155 Isolate* isolate_; |
| 156 |
| 157 Handle<Object> wasm_obj_; |
| 158 uint32_t wasm_func_index_; |
| 159 Handle<AbstractCode> code_; |
| 160 int offset_; |
| 161 |
| 162 friend class FrameArrayIterator; |
| 163 }; |
| 164 |
| 165 class FrameArrayIterator { |
| 166 public: |
| 167 FrameArrayIterator(Isolate* isolate, Handle<FrameArray> array, |
| 168 int frame_ix = 0); |
| 169 |
| 170 StackFrameBase* Frame(); |
| 171 |
| 172 bool HasNext() const; |
| 173 void Next(); |
69 | 174 |
70 private: | 175 private: |
71 Isolate* isolate_; | 176 Isolate* isolate_; |
72 Handle<Object> receiver_; | 177 |
73 Handle<JSFunction> fun_; | 178 Handle<FrameArray> array_; |
74 int32_t pos_ = -1; | 179 int next_frame_ix_; |
75 Handle<JSObject> wasm_obj_; | 180 |
76 uint32_t wasm_func_index_ = static_cast<uint32_t>(-1); | 181 WasmStackFrame wasm_frame_; |
| 182 JSStackFrame js_frame_; |
77 }; | 183 }; |
78 | 184 |
79 // Determines how stack trace collection skips frames. | 185 // Determines how stack trace collection skips frames. |
80 enum FrameSkipMode { | 186 enum FrameSkipMode { |
81 // Unconditionally skips the first frame. Used e.g. when the Error constructor | 187 // Unconditionally skips the first frame. Used e.g. when the Error constructor |
82 // is called, in which case the first frame is always a BUILTIN_EXIT frame. | 188 // is called, in which case the first frame is always a BUILTIN_EXIT frame. |
83 SKIP_FIRST, | 189 SKIP_FIRST, |
84 // Skip all frames until a specified caller function is seen. | 190 // Skip all frames until a specified caller function is seen. |
85 SKIP_UNTIL_SEEN, | 191 SKIP_UNTIL_SEEN, |
86 SKIP_NONE, | 192 SKIP_NONE, |
(...skipping 13 matching lines...) Expand all Loading... |
100 Handle<Object> arg0, Handle<Object> arg1, Handle<Object> arg2, | 206 Handle<Object> arg0, Handle<Object> arg1, Handle<Object> arg2, |
101 FrameSkipMode mode); | 207 FrameSkipMode mode); |
102 | 208 |
103 // Formats a textual stack trace from the given structured stack trace. | 209 // Formats a textual stack trace from the given structured stack trace. |
104 // Note that this can call arbitrary JS code through Error.prepareStackTrace. | 210 // Note that this can call arbitrary JS code through Error.prepareStackTrace. |
105 static MaybeHandle<Object> FormatStackTrace(Isolate* isolate, | 211 static MaybeHandle<Object> FormatStackTrace(Isolate* isolate, |
106 Handle<JSObject> error, | 212 Handle<JSObject> error, |
107 Handle<Object> stack_trace); | 213 Handle<Object> stack_trace); |
108 }; | 214 }; |
109 | 215 |
110 class CallSiteUtils : public AllStatic { | |
111 public: | |
112 static MaybeHandle<Object> Construct(Isolate* isolate, | |
113 Handle<Object> receiver, | |
114 Handle<Object> fun, Handle<Object> pos, | |
115 Handle<Object> strict_mode); | |
116 | |
117 static MaybeHandle<String> ToString(Isolate* isolate, Handle<Object> recv); | |
118 }; | |
119 | |
120 #define MESSAGE_TEMPLATES(T) \ | 216 #define MESSAGE_TEMPLATES(T) \ |
121 /* Error */ \ | 217 /* Error */ \ |
122 T(None, "") \ | 218 T(None, "") \ |
123 T(CyclicProto, "Cyclic __proto__ value") \ | 219 T(CyclicProto, "Cyclic __proto__ value") \ |
124 T(Debugger, "Debugger: %") \ | 220 T(Debugger, "Debugger: %") \ |
125 T(DebuggerLoading, "Error loading debugger") \ | 221 T(DebuggerLoading, "Error loading debugger") \ |
126 T(DefaultOptionsMissing, "Internal % error. Default options are missing.") \ | 222 T(DefaultOptionsMissing, "Internal % error. Default options are missing.") \ |
127 T(UncaughtException, "Uncaught %") \ | 223 T(UncaughtException, "Uncaught %") \ |
128 T(Unsupported, "Not supported") \ | 224 T(Unsupported, "Not supported") \ |
129 T(WrongServiceType, "Internal error, wrong service type: %") \ | 225 T(WrongServiceType, "Internal error, wrong service type: %") \ |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 static Handle<String> GetMessage(Isolate* isolate, Handle<Object> data); | 678 static Handle<String> GetMessage(Isolate* isolate, Handle<Object> data); |
583 static std::unique_ptr<char[]> GetLocalizedMessage(Isolate* isolate, | 679 static std::unique_ptr<char[]> GetLocalizedMessage(Isolate* isolate, |
584 Handle<Object> data); | 680 Handle<Object> data); |
585 }; | 681 }; |
586 | 682 |
587 | 683 |
588 } // namespace internal | 684 } // namespace internal |
589 } // namespace v8 | 685 } // namespace v8 |
590 | 686 |
591 #endif // V8_MESSAGES_H_ | 687 #endif // V8_MESSAGES_H_ |
OLD | NEW |