/src/node/deps/v8/include/v8-message.h
Line | Count | Source |
1 | | // Copyright 2021 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 INCLUDE_V8_MESSAGE_H_ |
6 | | #define INCLUDE_V8_MESSAGE_H_ |
7 | | |
8 | | #include <stdio.h> |
9 | | |
10 | | #include <iosfwd> |
11 | | |
12 | | #include "v8-callbacks.h" // NOLINT(build/include_directory) |
13 | | #include "v8-local-handle.h" // NOLINT(build/include_directory) |
14 | | #include "v8-maybe.h" // NOLINT(build/include_directory) |
15 | | #include "v8-primitive.h" // NOLINT(build/include_directory) |
16 | | #include "v8config.h" // NOLINT(build/include_directory) |
17 | | |
18 | | namespace v8 { |
19 | | |
20 | | class Integer; |
21 | | class PrimitiveArray; |
22 | | class StackTrace; |
23 | | class String; |
24 | | class Value; |
25 | | |
26 | | /** |
27 | | * The optional attributes of ScriptOrigin. |
28 | | */ |
29 | | class ScriptOriginOptions { |
30 | | public: |
31 | | V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin = false, |
32 | | bool is_opaque = false, bool is_wasm = false, |
33 | | bool is_module = false) |
34 | 2.59k | : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) | |
35 | 2.59k | (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) | |
36 | 2.59k | (is_module ? kIsModule : 0)) {} |
37 | | V8_INLINE ScriptOriginOptions(int flags) |
38 | | : flags_(flags & |
39 | 0 | (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {} |
40 | | |
41 | 0 | bool IsSharedCrossOrigin() const { |
42 | 0 | return (flags_ & kIsSharedCrossOrigin) != 0; |
43 | 0 | } |
44 | 0 | bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; } |
45 | 0 | bool IsWasm() const { return (flags_ & kIsWasm) != 0; } |
46 | 0 | bool IsModule() const { return (flags_ & kIsModule) != 0; } |
47 | | |
48 | 0 | int Flags() const { return flags_; } |
49 | | |
50 | | private: |
51 | | enum { |
52 | | kIsSharedCrossOrigin = 1, |
53 | | kIsOpaque = 1 << 1, |
54 | | kIsWasm = 1 << 2, |
55 | | kIsModule = 1 << 3 |
56 | | }; |
57 | | const int flags_; |
58 | | }; |
59 | | |
60 | | /** |
61 | | * The origin, within a file, of a script. |
62 | | */ |
63 | | class V8_EXPORT ScriptOrigin { |
64 | | public: |
65 | | V8_INLINE ScriptOrigin(Local<Value> resource_name, |
66 | | int resource_line_offset = 0, |
67 | | int resource_column_offset = 0, |
68 | | bool resource_is_shared_cross_origin = false, |
69 | | int script_id = -1, |
70 | | Local<Value> source_map_url = Local<Value>(), |
71 | | bool resource_is_opaque = false, bool is_wasm = false, |
72 | | bool is_module = false, |
73 | | Local<Data> host_defined_options = Local<Data>()) |
74 | 2.59k | : resource_name_(resource_name), |
75 | 2.59k | resource_line_offset_(resource_line_offset), |
76 | 2.59k | resource_column_offset_(resource_column_offset), |
77 | 2.59k | options_(resource_is_shared_cross_origin, resource_is_opaque, is_wasm, |
78 | 2.59k | is_module), |
79 | 2.59k | script_id_(script_id), |
80 | 2.59k | source_map_url_(source_map_url), |
81 | 2.59k | host_defined_options_(host_defined_options) { |
82 | 2.59k | VerifyHostDefinedOptions(); |
83 | 2.59k | } |
84 | | |
85 | | V8_INLINE Local<Value> ResourceName() const; |
86 | | V8_INLINE int LineOffset() const; |
87 | | V8_INLINE int ColumnOffset() const; |
88 | | V8_INLINE int ScriptId() const; |
89 | | V8_INLINE Local<Value> SourceMapUrl() const; |
90 | | V8_INLINE Local<Data> GetHostDefinedOptions() const; |
91 | 2.59k | V8_INLINE ScriptOriginOptions Options() const { return options_; } |
92 | | |
93 | | private: |
94 | | void VerifyHostDefinedOptions() const; |
95 | | Local<Value> resource_name_; |
96 | | int resource_line_offset_; |
97 | | int resource_column_offset_; |
98 | | ScriptOriginOptions options_; |
99 | | int script_id_; |
100 | | Local<Value> source_map_url_; |
101 | | Local<Data> host_defined_options_; |
102 | | }; |
103 | | |
104 | | /** |
105 | | * An error message. |
106 | | */ |
107 | | class V8_EXPORT Message { |
108 | | public: |
109 | | Local<String> Get() const; |
110 | | |
111 | | V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSource( |
112 | | Local<Context> context) const; |
113 | | V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSourceLine( |
114 | | Local<Context> context) const; |
115 | | |
116 | | /** |
117 | | * Returns the origin for the script from where the function causing the |
118 | | * error originates. |
119 | | */ |
120 | | ScriptOrigin GetScriptOrigin() const; |
121 | | |
122 | | /** |
123 | | * Returns the resource name for the script from where the function causing |
124 | | * the error originates. |
125 | | */ |
126 | | Local<Value> GetScriptResourceName() const; |
127 | | |
128 | | /** |
129 | | * Exception stack trace. By default stack traces are not captured for |
130 | | * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows |
131 | | * to change this option. |
132 | | */ |
133 | | Local<StackTrace> GetStackTrace() const; |
134 | | |
135 | | /** |
136 | | * Returns the number, 1-based, of the line where the error occurred. |
137 | | */ |
138 | | V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const; |
139 | | |
140 | | /** |
141 | | * Returns the index within the script of the first character where |
142 | | * the error occurred. |
143 | | */ |
144 | | int GetStartPosition() const; |
145 | | |
146 | | /** |
147 | | * Returns the index within the script of the last character where |
148 | | * the error occurred. |
149 | | */ |
150 | | int GetEndPosition() const; |
151 | | |
152 | | /** |
153 | | * Returns the Wasm function index where the error occurred. Returns -1 if |
154 | | * message is not from a Wasm script. |
155 | | */ |
156 | | int GetWasmFunctionIndex() const; |
157 | | |
158 | | /** |
159 | | * Returns the error level of the message. |
160 | | */ |
161 | | int ErrorLevel() const; |
162 | | |
163 | | /** |
164 | | * Returns the index within the line of the first character where |
165 | | * the error occurred. |
166 | | */ |
167 | | int GetStartColumn() const; |
168 | | V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const; |
169 | | |
170 | | /** |
171 | | * Returns the index within the line of the last character where |
172 | | * the error occurred. |
173 | | */ |
174 | | int GetEndColumn() const; |
175 | | V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const; |
176 | | |
177 | | /** |
178 | | * Passes on the value set by the embedder when it fed the script from which |
179 | | * this Message was generated to V8. |
180 | | */ |
181 | | bool IsSharedCrossOrigin() const; |
182 | | bool IsOpaque() const; |
183 | | |
184 | | /** |
185 | | * If provided, the callback can be used to selectively include |
186 | | * or redact frames based on their script names. (true to include a frame) |
187 | | */ |
188 | | static void PrintCurrentStackTrace( |
189 | | Isolate* isolate, std::ostream& out, |
190 | | PrintCurrentStackTraceFilterCallback should_include_frame_callback = |
191 | | nullptr); |
192 | | |
193 | | static const int kNoLineNumberInfo = 0; |
194 | | static const int kNoColumnInfo = 0; |
195 | | static const int kNoScriptIdInfo = 0; |
196 | | static const int kNoWasmFunctionIndexInfo = -1; |
197 | | }; |
198 | | |
199 | 2.62k | Local<Value> ScriptOrigin::ResourceName() const { return resource_name_; } |
200 | | |
201 | 2.59k | Local<Data> ScriptOrigin::GetHostDefinedOptions() const { |
202 | 2.59k | return host_defined_options_; |
203 | 2.59k | } |
204 | | |
205 | 2.59k | int ScriptOrigin::LineOffset() const { return resource_line_offset_; } |
206 | | |
207 | 2.59k | int ScriptOrigin::ColumnOffset() const { return resource_column_offset_; } |
208 | | |
209 | 0 | int ScriptOrigin::ScriptId() const { return script_id_; } |
210 | | |
211 | 2.62k | Local<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; } |
212 | | |
213 | | } // namespace v8 |
214 | | |
215 | | #endif // INCLUDE_V8_MESSAGE_H_ |