|
|
|||
File indexing completed on 2026-01-07 10:09:57
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_DEBUG_H_ 0006 #define INCLUDE_V8_DEBUG_H_ 0007 0008 #include <stdint.h> 0009 0010 #include "v8-script.h" // NOLINT(build/include_directory) 0011 #include "v8config.h" // NOLINT(build/include_directory) 0012 0013 namespace v8 { 0014 0015 class Isolate; 0016 class String; 0017 0018 /** 0019 * A single JavaScript stack frame. 0020 */ 0021 class V8_EXPORT StackFrame { 0022 public: 0023 /** 0024 * Returns the source location, 0-based, for the associated function call. 0025 */ 0026 Location GetLocation() const; 0027 0028 /** 0029 * Returns the number, 1-based, of the line for the associate function call. 0030 * This method will return Message::kNoLineNumberInfo if it is unable to 0031 * retrieve the line number, or if kLineNumber was not passed as an option 0032 * when capturing the StackTrace. 0033 */ 0034 int GetLineNumber() const { return GetLocation().GetLineNumber() + 1; } 0035 0036 /** 0037 * Returns the 1-based column offset on the line for the associated function 0038 * call. 0039 * This method will return Message::kNoColumnInfo if it is unable to retrieve 0040 * the column number, or if kColumnOffset was not passed as an option when 0041 * capturing the StackTrace. 0042 */ 0043 int GetColumn() const { return GetLocation().GetColumnNumber() + 1; } 0044 0045 /** 0046 * Returns zero based source position (character offset) for the associated 0047 * function. 0048 */ 0049 int GetSourcePosition() const; 0050 0051 /** 0052 * Returns the id of the script for the function for this StackFrame. 0053 * This method will return Message::kNoScriptIdInfo if it is unable to 0054 * retrieve the script id, or if kScriptId was not passed as an option when 0055 * capturing the StackTrace. 0056 */ 0057 int GetScriptId() const; 0058 0059 /** 0060 * Returns the name of the resource that contains the script for the 0061 * function for this StackFrame. 0062 */ 0063 Local<String> GetScriptName() const; 0064 0065 /** 0066 * Returns the name of the resource that contains the script for the 0067 * function for this StackFrame or sourceURL value if the script name 0068 * is undefined and its source ends with //# sourceURL=... string or 0069 * deprecated //@ sourceURL=... string. 0070 */ 0071 Local<String> GetScriptNameOrSourceURL() const; 0072 0073 /** 0074 * Returns the source of the script for the function for this StackFrame. 0075 */ 0076 Local<String> GetScriptSource() const; 0077 0078 /** 0079 * Returns the source mapping URL (if one is present) of the script for 0080 * the function for this StackFrame. 0081 */ 0082 Local<String> GetScriptSourceMappingURL() const; 0083 0084 /** 0085 * Returns the name of the function associated with this stack frame. 0086 */ 0087 Local<String> GetFunctionName() const; 0088 0089 /** 0090 * Returns whether or not the associated function is compiled via a call to 0091 * eval(). 0092 */ 0093 bool IsEval() const; 0094 0095 /** 0096 * Returns whether or not the associated function is called as a 0097 * constructor via "new". 0098 */ 0099 bool IsConstructor() const; 0100 0101 /** 0102 * Returns whether or not the associated functions is defined in wasm. 0103 */ 0104 bool IsWasm() const; 0105 0106 /** 0107 * Returns whether or not the associated function is defined by the user. 0108 */ 0109 bool IsUserJavaScript() const; 0110 }; 0111 0112 /** 0113 * Representation of a JavaScript stack trace. The information collected is a 0114 * snapshot of the execution stack and the information remains valid after 0115 * execution continues. 0116 */ 0117 class V8_EXPORT StackTrace { 0118 public: 0119 /** 0120 * Flags that determine what information is placed captured for each 0121 * StackFrame when grabbing the current stack trace. 0122 * Note: these options are deprecated and we always collect all available 0123 * information (kDetailed). 0124 */ 0125 enum StackTraceOptions { 0126 kLineNumber = 1, 0127 kColumnOffset = 1 << 1 | kLineNumber, 0128 kScriptName = 1 << 2, 0129 kFunctionName = 1 << 3, 0130 kIsEval = 1 << 4, 0131 kIsConstructor = 1 << 5, 0132 kScriptNameOrSourceURL = 1 << 6, 0133 kScriptId = 1 << 7, 0134 kExposeFramesAcrossSecurityOrigins = 1 << 8, 0135 kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName, 0136 kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL 0137 }; 0138 0139 /** 0140 * Returns the (unique) ID of this stack trace. 0141 */ 0142 int GetID() const; 0143 0144 /** 0145 * Returns a StackFrame at a particular index. 0146 */ 0147 Local<StackFrame> GetFrame(Isolate* isolate, uint32_t index) const; 0148 0149 /** 0150 * Returns the number of StackFrames. 0151 */ 0152 int GetFrameCount() const; 0153 0154 /** 0155 * Grab a snapshot of the current JavaScript execution stack. 0156 * 0157 * \param frame_limit The maximum number of stack frames we want to capture. 0158 * \param options Enumerates the set of things we will capture for each 0159 * StackFrame. 0160 */ 0161 static Local<StackTrace> CurrentStackTrace( 0162 Isolate* isolate, int frame_limit, StackTraceOptions options = kDetailed); 0163 0164 /** 0165 * Returns the first valid script name or source URL starting at the top of 0166 * the JS stack. The returned string is either an empty handle if no script 0167 * name/url was found or a non-zero-length string. 0168 * 0169 * This method is equivalent to calling StackTrace::CurrentStackTrace and 0170 * walking the resulting frames from the beginning until a non-empty script 0171 * name/url is found. The difference is that this method won't allocate 0172 * a stack trace. 0173 */ 0174 static Local<String> CurrentScriptNameOrSourceURL(Isolate* isolate); 0175 }; 0176 0177 } // namespace v8 0178 0179 #endif // INCLUDE_V8_DEBUG_H_
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|