Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-19 08:20:23

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   V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSource(
0112       Local<Context> context) const;
0113   V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSourceLine(
0114       Local<Context> context) const;
0115 
0116   /**
0117    * Returns the origin for the script from where the function causing the
0118    * error originates.
0119    */
0120   ScriptOrigin GetScriptOrigin() const;
0121 
0122   /**
0123    * Returns the resource name for the script from where the function causing
0124    * the error originates.
0125    */
0126   Local<Value> GetScriptResourceName() const;
0127 
0128   /**
0129    * Exception stack trace. By default stack traces are not captured for
0130    * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
0131    * to change this option.
0132    */
0133   Local<StackTrace> GetStackTrace() const;
0134 
0135   /**
0136    * Returns the number, 1-based, of the line where the error occurred.
0137    */
0138   V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
0139 
0140   /**
0141    * Returns the index within the script of the first character where
0142    * the error occurred.
0143    */
0144   int GetStartPosition() const;
0145 
0146   /**
0147    * Returns the index within the script of the last character where
0148    * the error occurred.
0149    */
0150   int GetEndPosition() const;
0151 
0152   /**
0153    * Returns the Wasm function index where the error occurred. Returns -1 if
0154    * message is not from a Wasm script.
0155    */
0156   int GetWasmFunctionIndex() const;
0157 
0158   /**
0159    * Returns the error level of the message.
0160    */
0161   int ErrorLevel() const;
0162 
0163   /**
0164    * Returns the index within the line of the first character where
0165    * the error occurred.
0166    */
0167   int GetStartColumn() const;
0168   V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
0169 
0170   /**
0171    * Returns the index within the line of the last character where
0172    * the error occurred.
0173    */
0174   int GetEndColumn() const;
0175   V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
0176 
0177   /**
0178    * Passes on the value set by the embedder when it fed the script from which
0179    * this Message was generated to V8.
0180    */
0181   bool IsSharedCrossOrigin() const;
0182   bool IsOpaque() const;
0183 
0184   /**
0185    * If provided, the callback can be used to selectively include
0186    * or redact frames based on their script names. (true to include a frame)
0187    */
0188   static void PrintCurrentStackTrace(
0189       Isolate* isolate, std::ostream& out,
0190       PrintCurrentStackTraceFilterCallback should_include_frame_callback =
0191           nullptr);
0192 
0193   static const int kNoLineNumberInfo = 0;
0194   static const int kNoColumnInfo = 0;
0195   static const int kNoScriptIdInfo = 0;
0196   static const int kNoWasmFunctionIndexInfo = -1;
0197 };
0198 
0199 Local<Value> ScriptOrigin::ResourceName() const { return resource_name_; }
0200 
0201 Local<Data> ScriptOrigin::GetHostDefinedOptions() const {
0202   return host_defined_options_;
0203 }
0204 
0205 int ScriptOrigin::LineOffset() const { return resource_line_offset_; }
0206 
0207 int ScriptOrigin::ColumnOffset() const { return resource_column_offset_; }
0208 
0209 int ScriptOrigin::ScriptId() const { return script_id_; }
0210 
0211 Local<Value> ScriptOrigin::SourceMapUrl() const { return source_map_url_; }
0212 
0213 }  // namespace v8
0214 
0215 #endif  // INCLUDE_V8_MESSAGE_H_