File indexing completed on 2025-02-21 10:05:25
0001
0002
0003
0004
0005 #ifndef INCLUDE_V8_MESSAGE_H_
0006 #define INCLUDE_V8_MESSAGE_H_
0007
0008 #include <stdio.h>
0009
0010 #include <iosfwd>
0011
0012 #include "v8-local-handle.h" // NOLINT(build/include_directory)
0013 #include "v8-maybe.h" // NOLINT(build/include_directory)
0014 #include "v8-primitive.h" // NOLINT(build/include_directory)
0015 #include "v8config.h" // NOLINT(build/include_directory)
0016
0017 namespace v8 {
0018
0019 class Integer;
0020 class PrimitiveArray;
0021 class StackTrace;
0022 class String;
0023 class Value;
0024
0025
0026
0027
0028 class ScriptOriginOptions {
0029 public:
0030 V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin = false,
0031 bool is_opaque = false, bool is_wasm = false,
0032 bool is_module = false)
0033 : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
0034 (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) |
0035 (is_module ? kIsModule : 0)) {}
0036 V8_INLINE ScriptOriginOptions(int flags)
0037 : flags_(flags &
0038 (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {}
0039
0040 bool IsSharedCrossOrigin() const {
0041 return (flags_ & kIsSharedCrossOrigin) != 0;
0042 }
0043 bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
0044 bool IsWasm() const { return (flags_ & kIsWasm) != 0; }
0045 bool IsModule() const { return (flags_ & kIsModule) != 0; }
0046
0047 int Flags() const { return flags_; }
0048
0049 private:
0050 enum {
0051 kIsSharedCrossOrigin = 1,
0052 kIsOpaque = 1 << 1,
0053 kIsWasm = 1 << 2,
0054 kIsModule = 1 << 3
0055 };
0056 const int flags_;
0057 };
0058
0059
0060
0061
0062 class V8_EXPORT ScriptOrigin {
0063 public:
0064 V8_DEPRECATE_SOON("Use constructor without the isolate.")
0065 V8_INLINE ScriptOrigin(Isolate* isolate, Local<Value> resource_name,
0066 int resource_line_offset = 0,
0067 int resource_column_offset = 0,
0068 bool resource_is_shared_cross_origin = false,
0069 int script_id = -1,
0070 Local<Value> source_map_url = Local<Value>(),
0071 bool resource_is_opaque = false, bool is_wasm = false,
0072 bool is_module = false,
0073 Local<Data> host_defined_options = Local<Data>())
0074 : resource_name_(resource_name),
0075 resource_line_offset_(resource_line_offset),
0076 resource_column_offset_(resource_column_offset),
0077 options_(resource_is_shared_cross_origin, resource_is_opaque, is_wasm,
0078 is_module),
0079 script_id_(script_id),
0080 source_map_url_(source_map_url),
0081 host_defined_options_(host_defined_options) {
0082 VerifyHostDefinedOptions();
0083 }
0084
0085 V8_INLINE ScriptOrigin(Local<Value> resource_name,
0086 int resource_line_offset = 0,
0087 int resource_column_offset = 0,
0088 bool resource_is_shared_cross_origin = false,
0089 int script_id = -1,
0090 Local<Value> source_map_url = Local<Value>(),
0091 bool resource_is_opaque = false, bool is_wasm = false,
0092 bool is_module = false,
0093 Local<Data> host_defined_options = Local<Data>())
0094 : resource_name_(resource_name),
0095 resource_line_offset_(resource_line_offset),
0096 resource_column_offset_(resource_column_offset),
0097 options_(resource_is_shared_cross_origin, resource_is_opaque, is_wasm,
0098 is_module),
0099 script_id_(script_id),
0100 source_map_url_(source_map_url),
0101 host_defined_options_(host_defined_options) {
0102 VerifyHostDefinedOptions();
0103 }
0104
0105 V8_INLINE Local<Value> ResourceName() const;
0106 V8_INLINE int LineOffset() const;
0107 V8_INLINE int ColumnOffset() const;
0108 V8_INLINE int ScriptId() const;
0109 V8_INLINE Local<Value> SourceMapUrl() const;
0110 V8_INLINE Local<Data> GetHostDefinedOptions() const;
0111 V8_INLINE ScriptOriginOptions Options() const { return options_; }
0112
0113 private:
0114 void VerifyHostDefinedOptions() const;
0115 Local<Value> resource_name_;
0116 int resource_line_offset_;
0117 int resource_column_offset_;
0118 ScriptOriginOptions options_;
0119 int script_id_;
0120 Local<Value> source_map_url_;
0121 Local<Data> host_defined_options_;
0122 };
0123
0124
0125
0126
0127 class V8_EXPORT Message {
0128 public:
0129 Local<String> Get() const;
0130
0131
0132
0133
0134 Isolate* GetIsolate() const;
0135
0136 V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSource(
0137 Local<Context> context) const;
0138 V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSourceLine(
0139 Local<Context> context) const;
0140
0141
0142
0143
0144
0145 ScriptOrigin GetScriptOrigin() const;
0146
0147
0148
0149
0150
0151 Local<Value> GetScriptResourceName() const;
0152
0153
0154
0155
0156
0157
0158 Local<StackTrace> GetStackTrace() const;
0159
0160
0161
0162
0163 V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
0164
0165
0166
0167
0168
0169 int GetStartPosition() const;
0170
0171
0172
0173
0174
0175 int GetEndPosition() const;
0176
0177
0178
0179
0180
0181 int GetWasmFunctionIndex() const;
0182
0183
0184
0185
0186 int ErrorLevel() const;
0187
0188
0189
0190
0191
0192 int GetStartColumn() const;
0193 V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
0194
0195
0196
0197
0198
0199 int GetEndColumn() const;
0200 V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
0201
0202
0203
0204
0205
0206 bool IsSharedCrossOrigin() const;
0207 bool IsOpaque() const;
0208
0209 static void PrintCurrentStackTrace(Isolate* isolate, std::ostream& out);
0210
0211 static const int kNoLineNumberInfo = 0;
0212 static const int kNoColumnInfo = 0;
0213 static const int kNoScriptIdInfo = 0;
0214 static const int kNoWasmFunctionIndexInfo = -1;
0215 };
0216
0217 Local<Value> ScriptOrigin::ResourceName() const { return resource_name_; }
0218
0219 Local<Data> ScriptOrigin::GetHostDefinedOptions() const {
0220 return host_defined_options_;
0221 }
0222
0223 int ScriptOrigin::LineOffset() const { return resource_line_offset_; }
0224
0225 int ScriptOrigin::ColumnOffset() const { return resource_column_offset_; }
0226
0227 int ScriptOrigin::ScriptId() const { return script_id_; }
0228
0229 Local<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; }
0230
0231 }
0232
0233 #endif