Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-21 08:27:52

0001 // Copyright 2021 the V8 project authors. All rights reserved.
0002 // Use of this source code is governed by a BSD-style license that can be
0003 // found in the LICENSE file.
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-callbacks.h"     // NOLINT(build/include_directory)
0013 #include "v8-local-handle.h"  // NOLINT(build/include_directory)
0014 #include "v8-maybe.h"         // NOLINT(build/include_directory)
0015 #include "v8-primitive.h"     // NOLINT(build/include_directory)
0016 #include "v8config.h"         // NOLINT(build/include_directory)
0017 
0018 namespace v8 {
0019 
0020 class Integer;
0021 class PrimitiveArray;
0022 class StackTrace;
0023 class String;
0024 class Value;
0025 
0026 /**
0027  * The optional attributes of ScriptOrigin.
0028  */
0029 class ScriptOriginOptions {
0030  public:
0031   V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin = false,
0032                                 bool is_opaque = false, bool is_wasm = false,
0033                                 bool is_module = false)
0034       : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
0035                (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) |
0036                (is_module ? kIsModule : 0)) {}
0037   V8_INLINE ScriptOriginOptions(int flags)
0038       : flags_(flags &
0039                (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {}
0040 
0041   bool IsSharedCrossOrigin() const {
0042     return (flags_ & kIsSharedCrossOrigin) != 0;
0043   }
0044   bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
0045   bool IsWasm() const { return (flags_ & kIsWasm) != 0; }
0046   bool IsModule() const { return (flags_ & kIsModule) != 0; }
0047 
0048   int Flags() const { return flags_; }
0049 
0050  private:
0051   enum {
0052     kIsSharedCrossOrigin = 1,
0053     kIsOpaque = 1 << 1,
0054     kIsWasm = 1 << 2,
0055     kIsModule = 1 << 3
0056   };
0057   const int flags_;
0058 };
0059 
0060 /**
0061  * The origin, within a file, of a script.
0062  */
0063 class V8_EXPORT ScriptOrigin {
0064  public:
0065   V8_INLINE ScriptOrigin(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 Local<Value> ResourceName() const;
0086   V8_INLINE int LineOffset() const;
0087   V8_INLINE int ColumnOffset() const;
0088   V8_INLINE int ScriptId() const;
0089   V8_INLINE Local<Value> SourceMapUrl() const;
0090   V8_INLINE Local<Data> GetHostDefinedOptions() const;
0091   V8_INLINE ScriptOriginOptions Options() const { return options_; }
0092 
0093  private:
0094   void VerifyHostDefinedOptions() const;
0095   Local<Value> resource_name_;
0096   int resource_line_offset_;
0097   int resource_column_offset_;
0098   ScriptOriginOptions options_;
0099   int script_id_;
0100   Local<Value> source_map_url_;
0101   Local<Data> host_defined_options_;
0102 };
0103 
0104 /**
0105  * An error message.
0106  */
0107 class V8_EXPORT Message {
0108  public:
0109   Local<String> Get() const;
0110 
0111   /**
0112    * Return the isolate to which the Message belongs.
0113    */
0114   Isolate* GetIsolate() const;
0115 
0116   V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSource(
0117       Local<Context> context) const;
0118   V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSourceLine(
0119       Local<Context> context) const;
0120 
0121   /**
0122    * Returns the origin for the script from where the function causing the
0123    * error originates.
0124    */
0125   ScriptOrigin GetScriptOrigin() const;
0126 
0127   /**
0128    * Returns the resource name for the script from where the function causing
0129    * the error originates.
0130    */
0131   Local<Value> GetScriptResourceName() const;
0132 
0133   /**
0134    * Exception stack trace. By default stack traces are not captured for
0135    * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
0136    * to change this option.
0137    */
0138   Local<StackTrace> GetStackTrace() const;
0139 
0140   /**
0141    * Returns the number, 1-based, of the line where the error occurred.
0142    */
0143   V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
0144 
0145   /**
0146    * Returns the index within the script of the first character where
0147    * the error occurred.
0148    */
0149   int GetStartPosition() const;
0150 
0151   /**
0152    * Returns the index within the script of the last character where
0153    * the error occurred.
0154    */
0155   int GetEndPosition() const;
0156 
0157   /**
0158    * Returns the Wasm function index where the error occurred. Returns -1 if
0159    * message is not from a Wasm script.
0160    */
0161   int GetWasmFunctionIndex() const;
0162 
0163   /**
0164    * Returns the error level of the message.
0165    */
0166   int ErrorLevel() const;
0167 
0168   /**
0169    * Returns the index within the line of the first character where
0170    * the error occurred.
0171    */
0172   int GetStartColumn() const;
0173   V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
0174 
0175   /**
0176    * Returns the index within the line of the last character where
0177    * the error occurred.
0178    */
0179   int GetEndColumn() const;
0180   V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
0181 
0182   /**
0183    * Passes on the value set by the embedder when it fed the script from which
0184    * this Message was generated to V8.
0185    */
0186   bool IsSharedCrossOrigin() const;
0187   bool IsOpaque() const;
0188 
0189   /**
0190    * If provided, the callback can be used to selectively include
0191    * or redact frames based on their script names. (true to include a frame)
0192    */
0193   static void PrintCurrentStackTrace(
0194       Isolate* isolate, std::ostream& out,
0195       PrintCurrentStackTraceFilterCallback should_include_frame_callback =
0196           nullptr);
0197 
0198   static const int kNoLineNumberInfo = 0;
0199   static const int kNoColumnInfo = 0;
0200   static const int kNoScriptIdInfo = 0;
0201   static const int kNoWasmFunctionIndexInfo = -1;
0202 };
0203 
0204 Local<Value> ScriptOrigin::ResourceName() const { return resource_name_; }
0205 
0206 Local<Data> ScriptOrigin::GetHostDefinedOptions() const {
0207   return host_defined_options_;
0208 }
0209 
0210 int ScriptOrigin::LineOffset() const { return resource_line_offset_; }
0211 
0212 int ScriptOrigin::ColumnOffset() const { return resource_column_offset_; }
0213 
0214 int ScriptOrigin::ScriptId() const { return script_id_; }
0215 
0216 Local<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; }
0217 
0218 }  // namespace v8
0219 
0220 #endif  // INCLUDE_V8_MESSAGE_H_