/src/node/deps/v8/include/v8-handle-base.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2023 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 INCLUDE_V8_HANDLE_BASE_H_ |
6 | | #define INCLUDE_V8_HANDLE_BASE_H_ |
7 | | |
8 | | #include "v8-internal.h" // NOLINT(build/include_directory) |
9 | | |
10 | | namespace v8::api_internal { |
11 | | |
12 | | template <bool check_statically_enabled> |
13 | | class StackAllocated { |
14 | | public: |
15 | | V8_INLINE StackAllocated() = default; |
16 | | |
17 | | protected: |
18 | | struct no_checking_tag {}; |
19 | | static constexpr no_checking_tag do_not_check{}; |
20 | | |
21 | | V8_INLINE explicit StackAllocated(no_checking_tag) {} |
22 | | V8_INLINE explicit StackAllocated(const StackAllocated& other, |
23 | | no_checking_tag) {} |
24 | | |
25 | | V8_INLINE void VerifyOnStack() const {} |
26 | | }; |
27 | | |
28 | | template <> |
29 | | class V8_TRIVIAL_ABI StackAllocated<true> : public StackAllocated<false> { |
30 | | public: |
31 | 0 | V8_INLINE StackAllocated() { VerifyOnStack(); } |
32 | | |
33 | | #if V8_HAS_ATTRIBUTE_TRIVIAL_ABI |
34 | | // In this case, StackAllocated becomes not trivially copyable. |
35 | 0 | V8_INLINE StackAllocated(const StackAllocated& other) { VerifyOnStack(); } |
36 | | StackAllocated& operator=(const StackAllocated&) = default; |
37 | | #endif |
38 | | |
39 | | protected: |
40 | | V8_INLINE explicit StackAllocated(no_checking_tag tag) |
41 | 0 | : StackAllocated<false>(tag) {} |
42 | | V8_INLINE explicit StackAllocated(const StackAllocated& other, |
43 | | no_checking_tag tag) |
44 | 0 | : StackAllocated<false>(other, tag) {} |
45 | | |
46 | | V8_EXPORT void VerifyOnStack() const; |
47 | | }; |
48 | | |
49 | | /** |
50 | | * A base class for abstract handles containing indirect pointers. |
51 | | * These are useful regardless of whether direct local support is enabled. |
52 | | */ |
53 | | class IndirectHandleBase { |
54 | | public: |
55 | | // Returns true if the handle is empty. |
56 | 771M | V8_INLINE bool IsEmpty() const { return location_ == nullptr; } |
57 | | |
58 | | // Sets the handle to be empty. IsEmpty() will then return true. |
59 | 10.7M | V8_INLINE void Clear() { location_ = nullptr; } |
60 | | |
61 | | protected: |
62 | | friend class internal::ValueHelper; |
63 | | friend class internal::HandleHelper; |
64 | | |
65 | 1.08G | V8_INLINE IndirectHandleBase() = default; |
66 | | V8_INLINE IndirectHandleBase(const IndirectHandleBase& other) = default; |
67 | | V8_INLINE IndirectHandleBase& operator=(const IndirectHandleBase& that) = |
68 | | default; |
69 | | |
70 | | V8_INLINE explicit IndirectHandleBase(internal::Address* location) |
71 | 249M | : location_(location) {} |
72 | | |
73 | | // Returns the address of the actual heap object (tagged). |
74 | | // This method must be called only if the handle is not empty, otherwise it |
75 | | // will crash. |
76 | 16.6M | V8_INLINE internal::Address ptr() const { return *location_; } |
77 | | |
78 | | // Returns a reference to the slot (indirect pointer). |
79 | 927M | V8_INLINE internal::Address* const& slot() const { return location_; } |
80 | 109M | V8_INLINE internal::Address*& slot() { return location_; } |
81 | | |
82 | | // Returns the handler's "value" (direct or indirect pointer, depending on |
83 | | // whether direct local support is enabled). |
84 | | template <typename T, bool check_null = false> |
85 | 795M | V8_INLINE T* value() const { |
86 | 795M | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); |
87 | 795M | } Unexecuted instantiation: v8::Data* v8::api_internal::IndirectHandleBase::value<v8::Data, false>() const v8::Value* v8::api_internal::IndirectHandleBase::value<v8::Value, false>() const Line | Count | Source | 85 | 134M | V8_INLINE T* value() const { | 86 | 134M | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 134M | } |
v8::Object* v8::api_internal::IndirectHandleBase::value<v8::Object, false>() const Line | Count | Source | 85 | 290M | V8_INLINE T* value() const { | 86 | 290M | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 290M | } |
v8::Context* v8::api_internal::IndirectHandleBase::value<v8::Context, false>() const Line | Count | Source | 85 | 173M | V8_INLINE T* value() const { | 86 | 173M | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 173M | } |
Unexecuted instantiation: v8::Date* v8::api_internal::IndirectHandleBase::value<v8::Date, false>() const v8::FunctionTemplate* v8::api_internal::IndirectHandleBase::value<v8::FunctionTemplate, false>() const Line | Count | Source | 85 | 52.4M | V8_INLINE T* value() const { | 86 | 52.4M | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 52.4M | } |
v8::Template* v8::api_internal::IndirectHandleBase::value<v8::Template, false>() const Line | Count | Source | 85 | 21.4M | V8_INLINE T* value() const { | 86 | 21.4M | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 21.4M | } |
v8::Function* v8::api_internal::IndirectHandleBase::value<v8::Function, false>() const Line | Count | Source | 85 | 20.7M | V8_INLINE T* value() const { | 86 | 20.7M | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 20.7M | } |
v8::ObjectTemplate* v8::api_internal::IndirectHandleBase::value<v8::ObjectTemplate, false>() const Line | Count | Source | 85 | 26.9M | V8_INLINE T* value() const { | 86 | 26.9M | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 26.9M | } |
v8::Array* v8::api_internal::IndirectHandleBase::value<v8::Array, false>() const Line | Count | Source | 85 | 1.79M | V8_INLINE T* value() const { | 86 | 1.79M | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 1.79M | } |
v8::Number* v8::api_internal::IndirectHandleBase::value<v8::Number, false>() const Line | Count | Source | 85 | 9 | V8_INLINE T* value() const { | 86 | 9 | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 9 | } |
Unexecuted instantiation: v8::Int8Array* v8::api_internal::IndirectHandleBase::value<v8::Int8Array, true>() const v8::Uint8Array* v8::api_internal::IndirectHandleBase::value<v8::Uint8Array, true>() const Line | Count | Source | 85 | 507k | V8_INLINE T* value() const { | 86 | 507k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 507k | } |
Unexecuted instantiation: v8::Int16Array* v8::api_internal::IndirectHandleBase::value<v8::Int16Array, true>() const Unexecuted instantiation: v8::Uint16Array* v8::api_internal::IndirectHandleBase::value<v8::Uint16Array, true>() const v8::Int32Array* v8::api_internal::IndirectHandleBase::value<v8::Int32Array, true>() const Line | Count | Source | 85 | 339k | V8_INLINE T* value() const { | 86 | 339k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 339k | } |
v8::Uint32Array* v8::api_internal::IndirectHandleBase::value<v8::Uint32Array, true>() const Line | Count | Source | 85 | 888k | V8_INLINE T* value() const { | 86 | 888k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 888k | } |
Unexecuted instantiation: v8::Float32Array* v8::api_internal::IndirectHandleBase::value<v8::Float32Array, true>() const v8::Float64Array* v8::api_internal::IndirectHandleBase::value<v8::Float64Array, true>() const Line | Count | Source | 85 | 634k | V8_INLINE T* value() const { | 86 | 634k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 634k | } |
v8::BigInt64Array* v8::api_internal::IndirectHandleBase::value<v8::BigInt64Array, true>() const Line | Count | Source | 85 | 253k | V8_INLINE T* value() const { | 86 | 253k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 253k | } |
v8::Object* v8::api_internal::IndirectHandleBase::value<v8::Object, true>() const Line | Count | Source | 85 | 1.04M | V8_INLINE T* value() const { | 86 | 1.04M | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 1.04M | } |
v8::Int32* v8::api_internal::IndirectHandleBase::value<v8::Int32, false>() const Line | Count | Source | 85 | 119k | V8_INLINE T* value() const { | 86 | 119k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 119k | } |
v8::Context* v8::api_internal::IndirectHandleBase::value<v8::Context, true>() const Line | Count | Source | 85 | 143k | V8_INLINE T* value() const { | 86 | 143k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 143k | } |
Unexecuted instantiation: v8::Private* v8::api_internal::IndirectHandleBase::value<v8::Private, false>() const v8::Symbol* v8::api_internal::IndirectHandleBase::value<v8::Symbol, false>() const Line | Count | Source | 85 | 2.28M | V8_INLINE T* value() const { | 86 | 2.28M | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 2.28M | } |
v8::String* v8::api_internal::IndirectHandleBase::value<v8::String, false>() const Line | Count | Source | 85 | 32.2M | V8_INLINE T* value() const { | 86 | 32.2M | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 32.2M | } |
v8::ArrayBuffer* v8::api_internal::IndirectHandleBase::value<v8::ArrayBuffer, false>() const Line | Count | Source | 85 | 2.96M | V8_INLINE T* value() const { | 86 | 2.96M | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 2.96M | } |
v8::Int32Array* v8::api_internal::IndirectHandleBase::value<v8::Int32Array, false>() const Line | Count | Source | 85 | 380k | V8_INLINE T* value() const { | 86 | 380k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 380k | } |
v8::Uint32Array* v8::api_internal::IndirectHandleBase::value<v8::Uint32Array, false>() const Line | Count | Source | 85 | 893k | V8_INLINE T* value() const { | 86 | 893k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 893k | } |
v8::Script* v8::api_internal::IndirectHandleBase::value<v8::Script, false>() const Line | Count | Source | 85 | 4.06k | V8_INLINE T* value() const { | 86 | 4.06k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 4.06k | } |
Unexecuted instantiation: v8::Promise* v8::api_internal::IndirectHandleBase::value<v8::Promise, false>() const v8::Uint8Array* v8::api_internal::IndirectHandleBase::value<v8::Uint8Array, false>() const Line | Count | Source | 85 | 638k | V8_INLINE T* value() const { | 86 | 638k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 638k | } |
v8::Float64Array* v8::api_internal::IndirectHandleBase::value<v8::Float64Array, false>() const Line | Count | Source | 85 | 634k | V8_INLINE T* value() const { | 86 | 634k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 634k | } |
Unexecuted instantiation: v8::Array* v8::api_internal::IndirectHandleBase::value<v8::Array, true>() const v8::Function* v8::api_internal::IndirectHandleBase::value<v8::Function, true>() const Line | Count | Source | 85 | 2 | V8_INLINE T* value() const { | 86 | 2 | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 2 | } |
v8::Uint32* v8::api_internal::IndirectHandleBase::value<v8::Uint32, false>() const Line | Count | Source | 85 | 1.33k | V8_INLINE T* value() const { | 86 | 1.33k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 1.33k | } |
Unexecuted instantiation: v8::Promise* v8::api_internal::IndirectHandleBase::value<v8::Promise, true>() const v8::Name* v8::api_internal::IndirectHandleBase::value<v8::Name, false>() const Line | Count | Source | 85 | 1.18M | V8_INLINE T* value() const { | 86 | 1.18M | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 1.18M | } |
Unexecuted instantiation: v8::Module* v8::api_internal::IndirectHandleBase::value<v8::Module, false>() const Unexecuted instantiation: v8::Module* v8::api_internal::IndirectHandleBase::value<v8::Module, true>() const v8::PrimitiveArray* v8::api_internal::IndirectHandleBase::value<v8::PrimitiveArray, false>() const Line | Count | Source | 85 | 272k | V8_INLINE T* value() const { | 86 | 272k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 272k | } |
v8::ArrayBufferView* v8::api_internal::IndirectHandleBase::value<v8::ArrayBufferView, false>() const Line | Count | Source | 85 | 529k | V8_INLINE T* value() const { | 86 | 529k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 529k | } |
Unexecuted instantiation: v8::UnboundModuleScript* v8::api_internal::IndirectHandleBase::value<v8::UnboundModuleScript, false>() const Unexecuted instantiation: v8::FixedArray* v8::api_internal::IndirectHandleBase::value<v8::FixedArray, false>() const Unexecuted instantiation: v8::ModuleRequest* v8::api_internal::IndirectHandleBase::value<v8::ModuleRequest, false>() const v8::Boolean* v8::api_internal::IndirectHandleBase::value<v8::Boolean, false>() const Line | Count | Source | 85 | 126k | V8_INLINE T* value() const { | 86 | 126k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 126k | } |
Unexecuted instantiation: v8::Promise::Resolver* v8::api_internal::IndirectHandleBase::value<v8::Promise::Resolver, false>() const Unexecuted instantiation: v8::SharedArrayBuffer* v8::api_internal::IndirectHandleBase::value<v8::SharedArrayBuffer, false>() const v8::Value* v8::api_internal::IndirectHandleBase::value<v8::Value, true>() const Line | Count | Source | 85 | 2 | V8_INLINE T* value() const { | 86 | 2 | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 2 | } |
Unexecuted instantiation: v8::ArrayBuffer* v8::api_internal::IndirectHandleBase::value<v8::ArrayBuffer, true>() const v8::Integer* v8::api_internal::IndirectHandleBase::value<v8::Integer, false>() const Line | Count | Source | 85 | 1.08k | V8_INLINE T* value() const { | 86 | 1.08k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 1.08k | } |
Unexecuted instantiation: v8::Set* v8::api_internal::IndirectHandleBase::value<v8::Set, false>() const v8::UnboundScript* v8::api_internal::IndirectHandleBase::value<v8::UnboundScript, false>() const Line | Count | Source | 85 | 3.09k | V8_INLINE T* value() const { | 86 | 3.09k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 3.09k | } |
v8::UnboundScript* v8::api_internal::IndirectHandleBase::value<v8::UnboundScript, true>() const Line | Count | Source | 85 | 1.03k | V8_INLINE T* value() const { | 86 | 1.03k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 1.03k | } |
v8::Message* v8::api_internal::IndirectHandleBase::value<v8::Message, false>() const Line | Count | Source | 85 | 1.48M | V8_INLINE T* value() const { | 86 | 1.48M | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 1.48M | } |
v8::BigInt64Array* v8::api_internal::IndirectHandleBase::value<v8::BigInt64Array, false>() const Line | Count | Source | 85 | 253k | V8_INLINE T* value() const { | 86 | 253k | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 253k | } |
Unexecuted instantiation: v8::StackFrame* v8::api_internal::IndirectHandleBase::value<v8::StackFrame, false>() const Unexecuted instantiation: v8::StackTrace* v8::api_internal::IndirectHandleBase::value<v8::StackTrace, false>() const Unexecuted instantiation: v8::BigInt* v8::api_internal::IndirectHandleBase::value<v8::BigInt, false>() const Unexecuted instantiation: v8::WasmModuleObject* v8::api_internal::IndirectHandleBase::value<v8::WasmModuleObject, false>() const v8::Map* v8::api_internal::IndirectHandleBase::value<v8::Map, false>() const Line | Count | Source | 85 | 25.0M | V8_INLINE T* value() const { | 86 | 25.0M | return internal::ValueHelper::SlotAsValue<T, check_null>(slot()); | 87 | 25.0M | } |
Unexecuted instantiation: v8::Proxy* v8::api_internal::IndirectHandleBase::value<v8::Proxy, false>() const Unexecuted instantiation: v8::External* v8::api_internal::IndirectHandleBase::value<v8::External, false>() const Unexecuted instantiation: v8::WasmMemoryObject* v8::api_internal::IndirectHandleBase::value<v8::WasmMemoryObject, false>() const Unexecuted instantiation: v8::WasmMemoryObject* v8::api_internal::IndirectHandleBase::value<v8::WasmMemoryObject, true>() const Unexecuted instantiation: v8::ArrayBufferView* v8::api_internal::IndirectHandleBase::value<v8::ArrayBufferView, true>() const Unexecuted instantiation: v8::TypedArray* v8::api_internal::IndirectHandleBase::value<v8::TypedArray, false>() const Unexecuted instantiation: v8::DataView* v8::api_internal::IndirectHandleBase::value<v8::DataView, false>() const Unexecuted instantiation: v8::FunctionTemplate* v8::api_internal::IndirectHandleBase::value<v8::FunctionTemplate, true>() const |
88 | | |
89 | | private: |
90 | | internal::Address* location_ = nullptr; |
91 | | }; |
92 | | |
93 | | #ifdef V8_ENABLE_DIRECT_LOCAL |
94 | | |
95 | | /** |
96 | | * A base class for abstract handles containing direct pointers. |
97 | | * These are only possible when conservative stack scanning is enabled. |
98 | | */ |
99 | | class DirectHandleBase { |
100 | | public: |
101 | | // Returns true if the handle is empty. |
102 | | V8_INLINE bool IsEmpty() const { |
103 | | return ptr_ == internal::ValueHelper::kEmpty; |
104 | | } |
105 | | |
106 | | // Sets the handle to be empty. IsEmpty() will then return true. |
107 | | V8_INLINE void Clear() { ptr_ = internal::ValueHelper::kEmpty; } |
108 | | |
109 | | protected: |
110 | | friend class internal::ValueHelper; |
111 | | friend class internal::HandleHelper; |
112 | | |
113 | | V8_INLINE DirectHandleBase() = default; |
114 | | V8_INLINE DirectHandleBase(const DirectHandleBase& other) = default; |
115 | | V8_INLINE DirectHandleBase& operator=(const DirectHandleBase& that) = default; |
116 | | |
117 | | V8_INLINE explicit DirectHandleBase(internal::Address ptr) : ptr_(ptr) {} |
118 | | |
119 | | // Returns the address of the referenced object. |
120 | | V8_INLINE internal::Address ptr() const { return ptr_; } |
121 | | |
122 | | // Returns the handler's "value" (direct pointer, as direct local support |
123 | | // is guaranteed to be enabled here). |
124 | | template <typename T, bool check_null = false> |
125 | | V8_INLINE T* value() const { |
126 | | return reinterpret_cast<T*>(ptr_); |
127 | | } |
128 | | |
129 | | private: |
130 | | internal::Address ptr_ = internal::ValueHelper::kEmpty; |
131 | | }; |
132 | | |
133 | | #endif // V8_ENABLE_DIRECT_LOCAL |
134 | | |
135 | | } // namespace v8::api_internal |
136 | | |
137 | | #endif // INCLUDE_V8_HANDLE_BASE_H_ |