1 // Copyright 2018 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_OBJECTS_CALL_SITE_INFO_H_ 6 #define V8_OBJECTS_CALL_SITE_INFO_H_ 7 8 #include "src/objects/struct.h" 9 #include "torque-generated/bit-fields.h" 10 11 // Has to be the last include (doesn't have include guards): 12 #include "src/objects/object-macros.h" 13 14 namespace v8 { 15 namespace internal { 16 17 class MessageLocation; 18 class WasmInstanceObject; 19 class StructBodyDescriptor; 20 21 #include "torque-generated/src/objects/call-site-info-tq.inc" 22 23 class CallSiteInfo : public TorqueGeneratedCallSiteInfo<CallSiteInfo, Struct> { 24 public: 25 NEVER_READ_ONLY_SPACE 26 DEFINE_TORQUE_GENERATED_CALL_SITE_INFO_FLAGS() 27 28 #if V8_ENABLE_WEBASSEMBLY 29 inline bool IsWasm() const; 30 inline bool IsAsmJsWasm() const; 31 inline bool IsAsmJsAtNumberConversion() const; 32 #endif // V8_ENABLE_WEBASSEMBLY 33 34 inline bool IsStrict() const; 35 inline bool IsConstructor() const; 36 inline bool IsAsync() const; 37 bool IsEval() const; 38 bool IsUserJavaScript() const; 39 bool IsSubjectToDebugging() const; 40 bool IsMethodCall() const; 41 bool IsToplevel() const; 42 bool IsPromiseAll() const; 43 bool IsPromiseAllSettled() const; 44 bool IsPromiseAny() const; 45 bool IsNative() const; 46 47 DECL_ACCESSORS(code_object, HeapObject) 48 49 // Dispatched behavior. 50 DECL_VERIFIER(CallSiteInfo) 51 52 // Used to signal that the requested field is unknown. 53 static constexpr int kUnknown = kNoSourcePosition; 54 55 V8_EXPORT_PRIVATE static int GetLineNumber(Handle<CallSiteInfo> info); 56 V8_EXPORT_PRIVATE static int GetColumnNumber(Handle<CallSiteInfo> info); 57 58 static int GetEnclosingLineNumber(Handle<CallSiteInfo> info); 59 static int GetEnclosingColumnNumber(Handle<CallSiteInfo> info); 60 61 // Returns the script ID if one is attached, 62 // Message::kNoScriptIdInfo otherwise. 63 static MaybeHandle<Script> GetScript(Isolate* isolate, 64 Handle<CallSiteInfo> info); 65 int GetScriptId() const; 66 Object GetScriptName() const; 67 Object GetScriptNameOrSourceURL() const; 68 Object GetScriptSource() const; 69 Object GetScriptSourceMappingURL() const; 70 71 static Handle<PrimitiveHeapObject> GetEvalOrigin(Handle<CallSiteInfo> info); 72 V8_EXPORT_PRIVATE static Handle<PrimitiveHeapObject> GetFunctionName( 73 Handle<CallSiteInfo> info); 74 static Handle<String> GetFunctionDebugName(Handle<CallSiteInfo> info); 75 static Handle<Object> GetMethodName(Handle<CallSiteInfo> info); 76 static Handle<Object> GetTypeName(Handle<CallSiteInfo> info); 77 78 #if V8_ENABLE_WEBASSEMBLY 79 // These methods are only valid for Wasm and asm.js Wasm frames. 80 uint32_t GetWasmFunctionIndex() const; 81 WasmInstanceObject GetWasmInstance() const; 82 static Handle<Object> GetWasmModuleName(Handle<CallSiteInfo> info); 83 #endif // V8_ENABLE_WEBASSEMBLY 84 85 // Returns the 0-based source position, which is the offset into the 86 // Script in case of JavaScript and Asm.js, and the bytecode offset 87 // in the module in case of actual Wasm. In case of async promise 88 // combinator frames, this returns the index of the promise. 89 static int GetSourcePosition(Handle<CallSiteInfo> info); 90 91 // Attempts to fill the |location| based on the |info|, and avoids 92 // triggering source position table building for JavaScript frames. 93 static bool ComputeLocation(Handle<CallSiteInfo> info, 94 MessageLocation* location); 95 96 using BodyDescriptor = StructBodyDescriptor; 97 98 private: 99 static int ComputeSourcePosition(Handle<CallSiteInfo> info, int offset); 100 101 base::Optional<Script> GetScript() const; 102 SharedFunctionInfo GetSharedFunctionInfo() const; 103 104 TQ_OBJECT_CONSTRUCTORS(CallSiteInfo) 105 }; 106 107 class IncrementalStringBuilder; 108 void SerializeCallSiteInfo(Isolate* isolate, Handle<CallSiteInfo> frame, 109 IncrementalStringBuilder* builder); 110 V8_EXPORT_PRIVATE 111 MaybeHandle<String> SerializeCallSiteInfo(Isolate* isolate, 112 Handle<CallSiteInfo> frame); 113 114 } // namespace internal 115 } // namespace v8 116 117 #include "src/objects/object-macros-undef.h" 118 119 #endif // V8_OBJECTS_CALL_SITE_INFO_H_ 120