v8 14.1.146 (node 25.0.0)
V8 is Google's open source JavaScript engine
Loading...
Searching...
No Matches
v8-message.h
Go to the documentation of this file.
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
18namespace v8 {
19
20class Integer;
21class PrimitiveArray;
22class StackTrace;
23class String;
24class Value;
25
26/**
27 * The optional attributes of ScriptOrigin.
28 */
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 : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
35 (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) |
36 (is_module ? kIsModule : 0)) {}
38 : flags_(flags &
39 (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {}
40
41 bool IsSharedCrossOrigin() const {
42 return (flags_ & kIsSharedCrossOrigin) != 0;
43 }
44 bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
45 bool IsWasm() const { return (flags_ & kIsWasm) != 0; }
46 bool IsModule() const { return (flags_ & kIsModule) != 0; }
47
48 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 */
64 public:
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>())
75 resource_line_offset_(resource_line_offset),
76 resource_column_offset_(resource_column_offset),
77 options_(resource_is_shared_cross_origin, resource_is_opaque, is_wasm,
78 is_module),
79 script_id_(script_id),
82 VerifyHostDefinedOptions();
83 }
84
86 V8_INLINE int LineOffset() const;
87 V8_INLINE int ColumnOffset() const;
88 V8_INLINE int ScriptId() const;
91 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 */
108 public:
109 Local<String> Get() const;
110
111 /**
112 * Return the isolate to which the Message belongs.
113 */
115 "Use Isolate::GetCurrent() instead, which is guaranteed to return the "
116 "same isolate since https://crrev.com/c/6458560.")
117 Isolate* GetIsolate() const;
118
120 Local<Context> context) const;
122 Local<Context> context) const;
123
124 /**
125 * Returns the origin for the script from where the function causing the
126 * error originates.
127 */
129
130 /**
131 * Returns the resource name for the script from where the function causing
132 * the error originates.
133 */
135
136 /**
137 * Exception stack trace. By default stack traces are not captured for
138 * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
139 * to change this option.
140 */
142
143 /**
144 * Returns the number, 1-based, of the line where the error occurred.
145 */
147
148 /**
149 * Returns the index within the script of the first character where
150 * the error occurred.
151 */
152 int GetStartPosition() const;
153
154 /**
155 * Returns the index within the script of the last character where
156 * the error occurred.
157 */
158 int GetEndPosition() const;
159
160 /**
161 * Returns the Wasm function index where the error occurred. Returns -1 if
162 * message is not from a Wasm script.
163 */
165
166 /**
167 * Returns the error level of the message.
168 */
169 int ErrorLevel() const;
170
171 /**
172 * Returns the index within the line of the first character where
173 * the error occurred.
174 */
175 int GetStartColumn() const;
177
178 /**
179 * Returns the index within the line of the last character where
180 * the error occurred.
181 */
182 int GetEndColumn() const;
184
185 /**
186 * Passes on the value set by the embedder when it fed the script from which
187 * this Message was generated to V8.
188 */
190 bool IsOpaque() const;
191
192 /**
193 * If provided, the callback can be used to selectively include
194 * or redact frames based on their script names. (true to include a frame)
195 */
197 Isolate* isolate, std::ostream& out,
198 PrintCurrentStackTraceFilterCallback should_include_frame_callback =
199 nullptr);
200
201 static const int kNoLineNumberInfo = 0;
202 static const int kNoColumnInfo = 0;
203 static const int kNoScriptIdInfo = 0;
204 static const int kNoWasmFunctionIndexInfo = -1;
205};
206
207Local<Value> ScriptOrigin::ResourceName() const { return resource_name_; }
208
210 return host_defined_options_;
211}
212
213int ScriptOrigin::LineOffset() const { return resource_line_offset_; }
214
215int ScriptOrigin::ColumnOffset() const { return resource_column_offset_; }
216
217int ScriptOrigin::ScriptId() const { return script_id_; }
218
219Local<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; }
220
221} // namespace v8
222
223#endif // INCLUDE_V8_MESSAGE_H_
friend class Local
friend class MaybeLocal
Local< StackTrace > GetStackTrace() const
int GetEndPosition() const
V8_WARN_UNUSED_RESULT MaybeLocal< String > GetSourceLine(Local< Context > context) const
static const int kNoColumnInfo
Definition v8-message.h:202
int GetEndColumn() const
int GetWasmFunctionIndex() const
V8_WARN_UNUSED_RESULT Maybe< int > GetStartColumn(Local< Context > context) const
int ErrorLevel() const
static const int kNoLineNumberInfo
Definition v8-message.h:201
bool IsOpaque() const
V8_WARN_UNUSED_RESULT Maybe< int > GetLineNumber(Local< Context > context) const
ScriptOrigin GetScriptOrigin() const
int GetStartColumn() const
V8_WARN_UNUSED_RESULT MaybeLocal< String > GetSource(Local< Context > context) const
static const int kNoWasmFunctionIndexInfo
Definition v8-message.h:204
V8_WARN_UNUSED_RESULT Maybe< int > GetEndColumn(Local< Context > context) const
Local< Value > GetScriptResourceName() const
Local< String > Get() const
static void PrintCurrentStackTrace(Isolate *isolate, std::ostream &out, PrintCurrentStackTraceFilterCallback should_include_frame_callback=nullptr)
static const int kNoScriptIdInfo
Definition v8-message.h:203
bool IsSharedCrossOrigin() const
int GetStartPosition() const
V8_INLINE Local< Value > SourceMapUrl() const
Definition v8-message.h:219
V8_INLINE int ColumnOffset() const
Definition v8-message.h:215
V8_INLINE Local< Data > GetHostDefinedOptions() const
Definition v8-message.h:209
V8_INLINE int LineOffset() const
Definition v8-message.h:213
V8_INLINE ScriptOriginOptions Options() const
Definition v8-message.h:91
V8_INLINE ScriptOrigin(Local< Value > resource_name, int resource_line_offset=0, int resource_column_offset=0, bool resource_is_shared_cross_origin=false, int script_id=-1, Local< Value > source_map_url=Local< Value >(), bool resource_is_opaque=false, bool is_wasm=false, bool is_module=false, Local< Data > host_defined_options=Local< Data >())
Definition v8-message.h:65
V8_INLINE Local< Value > ResourceName() const
Definition v8-message.h:207
V8_INLINE int ScriptId() const
Definition v8-message.h:217
bool IsModule() const
Definition v8-message.h:46
bool IsOpaque() const
Definition v8-message.h:44
V8_INLINE ScriptOriginOptions(int flags)
Definition v8-message.h:37
bool IsSharedCrossOrigin() const
Definition v8-message.h:41
V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin=false, bool is_opaque=false, bool is_wasm=false, bool is_module=false)
Definition v8-message.h:31
#define V8_EXPORT
Definition v8config.h:860
#define V8_INLINE
Definition v8config.h:513
#define V8_DEPRECATED(message)
Definition v8config.h:619
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:684