Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:05:25

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-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  * The optional attributes of ScriptOrigin.
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  * The origin, within a file, of a script.
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  * An error message.
0126  */
0127 class V8_EXPORT Message {
0128  public:
0129   Local<String> Get() const;
0130 
0131   /**
0132    * Return the isolate to which the Message belongs.
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    * Returns the origin for the script from where the function causing the
0143    * error originates.
0144    */
0145   ScriptOrigin GetScriptOrigin() const;
0146 
0147   /**
0148    * Returns the resource name for the script from where the function causing
0149    * the error originates.
0150    */
0151   Local<Value> GetScriptResourceName() const;
0152 
0153   /**
0154    * Exception stack trace. By default stack traces are not captured for
0155    * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
0156    * to change this option.
0157    */
0158   Local<StackTrace> GetStackTrace() const;
0159 
0160   /**
0161    * Returns the number, 1-based, of the line where the error occurred.
0162    */
0163   V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
0164 
0165   /**
0166    * Returns the index within the script of the first character where
0167    * the error occurred.
0168    */
0169   int GetStartPosition() const;
0170 
0171   /**
0172    * Returns the index within the script of the last character where
0173    * the error occurred.
0174    */
0175   int GetEndPosition() const;
0176 
0177   /**
0178    * Returns the Wasm function index where the error occurred. Returns -1 if
0179    * message is not from a Wasm script.
0180    */
0181   int GetWasmFunctionIndex() const;
0182 
0183   /**
0184    * Returns the error level of the message.
0185    */
0186   int ErrorLevel() const;
0187 
0188   /**
0189    * Returns the index within the line of the first character where
0190    * the error occurred.
0191    */
0192   int GetStartColumn() const;
0193   V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
0194 
0195   /**
0196    * Returns the index within the line of the last character where
0197    * the error occurred.
0198    */
0199   int GetEndColumn() const;
0200   V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
0201 
0202   /**
0203    * Passes on the value set by the embedder when it fed the script from which
0204    * this Message was generated to V8.
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 }  // namespace v8
0232 
0233 #endif  // INCLUDE_V8_MESSAGE_H_