Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/node/v8-handle-base.h
$ cat -n /usr/include/node/v8-handle-base.h 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
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
: public StackAllocated
{ 30 public: 31 V8_INLINE StackAllocated() { VerifyOnStack(); } 32 33 #if V8_HAS_ATTRIBUTE_TRIVIAL_ABI 34 // In this case, StackAllocated becomes not trivially copyable. 35 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 : StackAllocated
(tag) {} 42 V8_INLINE explicit StackAllocated(const StackAllocated& other, 43 no_checking_tag tag) 44 : StackAllocated
(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 V8_INLINE bool IsEmpty() const { return location_ == nullptr; } 57 58 // Sets the handle to be empty. IsEmpty() will then return true. 59 V8_INLINE void Clear() { location_ = nullptr; } 60 61 protected: 62 friend class internal::ValueHelper; 63 friend class internal::HandleHelper; 64 65 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 : 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 V8_INLINE internal::Address ptr() const { return *location_; } 77 78 // Returns a reference to the slot (indirect pointer). 79 V8_INLINE internal::Address* const& slot() const { return location_; } 80 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
85 V8_INLINE T* value() const { 86 return internal::ValueHelper::SlotAsValue
(slot()); 87 } 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
125 V8_INLINE T* value() const { 126 return reinterpret_cast
(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_
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2026 MyWebUniversity.com ™