Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/nodejs/src/node_realm-inl.h
$ cat -n /usr/include/nodejs/src/node_realm-inl.h 1 #ifndef SRC_NODE_REALM_INL_H_ 2 #define SRC_NODE_REALM_INL_H_ 3 4 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 5 6 #include "cleanup_queue-inl.h" 7 #include "node_realm.h" 8 9 namespace node { 10 11 inline Realm* Realm::GetCurrent(v8::Isolate* isolate) { 12 if (UNLIKELY(!isolate->InContext())) return nullptr; 13 v8::HandleScope handle_scope(isolate); 14 return GetCurrent(isolate->GetCurrentContext()); 15 } 16 17 inline Realm* Realm::GetCurrent(v8::Local
context) { 18 if (UNLIKELY(!ContextEmbedderTag::IsNodeContext(context))) return nullptr; 19 return static_cast
( 20 context->GetAlignedPointerFromEmbedderData(ContextEmbedderIndex::kRealm)); 21 } 22 23 inline Realm* Realm::GetCurrent( 24 const v8::FunctionCallbackInfo
& info) { 25 return GetCurrent(info.GetIsolate()->GetCurrentContext()); 26 } 27 28 template
29 inline Realm* Realm::GetCurrent(const v8::PropertyCallbackInfo
& info) { 30 return GetCurrent(info.GetIsolate()->GetCurrentContext()); 31 } 32 33 inline IsolateData* Realm::isolate_data() const { 34 return env_->isolate_data(); 35 } 36 37 inline Environment* Realm::env() const { 38 return env_; 39 } 40 41 inline v8::Isolate* Realm::isolate() const { 42 return isolate_; 43 } 44 45 inline bool Realm::has_run_bootstrapping_code() const { 46 return has_run_bootstrapping_code_; 47 } 48 49 // static 50 template
51 inline T* Realm::GetBindingData(const v8::PropertyCallbackInfo
& info) { 52 return GetBindingData
(info.GetIsolate()->GetCurrentContext()); 53 } 54 55 // static 56 template
57 inline T* Realm::GetBindingData( 58 const v8::FunctionCallbackInfo
& info) { 59 return GetBindingData
(info.GetIsolate()->GetCurrentContext()); 60 } 61 62 // static 63 template
64 inline T* Realm::GetBindingData(v8::Local
context) { 65 BindingDataStore* map = 66 static_cast
(context->GetAlignedPointerFromEmbedderData( 67 ContextEmbedderIndex::kBindingDataStoreIndex)); 68 DCHECK_NOT_NULL(map); 69 constexpr size_t binding_index = static_cast
(T::binding_type_int); 70 static_assert(binding_index < std::tuple_size_v
); 71 auto ptr = (*map)[binding_index]; 72 if (UNLIKELY(!ptr)) return nullptr; 73 T* result = static_cast
(ptr.get()); 74 DCHECK_NOT_NULL(result); 75 DCHECK_EQ(result->realm(), GetCurrent(context)); 76 return result; 77 } 78 79 template
80 inline T* Realm::AddBindingData(v8::Local
context, 81 v8::Local
target) { 82 DCHECK_EQ(GetCurrent(context), this); 83 // This won't compile if T is not a BaseObject subclass. 84 BaseObjectPtr
item = MakeDetachedBaseObject
(this, target); 85 BindingDataStore* map = 86 static_cast
(context->GetAlignedPointerFromEmbedderData( 87 ContextEmbedderIndex::kBindingDataStoreIndex)); 88 DCHECK_NOT_NULL(map); 89 constexpr size_t binding_index = static_cast
(T::binding_type_int); 90 static_assert(binding_index < std::tuple_size_v
); 91 CHECK(!(*map)[binding_index]); // Should not insert the binding twice. 92 (*map)[binding_index] = item; 93 DCHECK_EQ(GetBindingData
(context), item.get()); 94 return item.get(); 95 } 96 97 inline BindingDataStore* Realm::binding_data_store() { 98 return &binding_data_store_; 99 } 100 101 template
102 void Realm::ForEachBaseObject(T&& iterator) const { 103 cleanup_queue_.ForEachBaseObject(std::forward
(iterator)); 104 } 105 106 void Realm::modify_base_object_count(int64_t delta) { 107 base_object_count_ += delta; 108 } 109 110 int64_t Realm::base_object_created_after_bootstrap() const { 111 return base_object_count_ - base_object_created_by_bootstrap_; 112 } 113 114 int64_t Realm::base_object_count() const { 115 return base_object_count_; 116 } 117 118 #define V(PropertyName, TypeName) \ 119 inline v8::Local
Realm::PropertyName() const { \ 120 return PersistentToLocal::Strong(PropertyName##_); \ 121 } \ 122 inline void Realm::set_##PropertyName(v8::Local
value) { \ 123 PropertyName##_.Reset(isolate(), value); \ 124 } 125 PER_REALM_STRONG_PERSISTENT_VALUES(V) 126 #undef V 127 128 v8::Local
Realm::context() const { 129 return PersistentToLocal::Strong(context_); 130 } 131 132 void Realm::AddCleanupHook(CleanupQueue::Callback fn, void* arg) { 133 cleanup_queue_.Add(fn, arg); 134 } 135 136 void Realm::RemoveCleanupHook(CleanupQueue::Callback fn, void* arg) { 137 cleanup_queue_.Remove(fn, arg); 138 } 139 140 bool Realm::HasCleanupHooks() const { 141 return !cleanup_queue_.empty(); 142 } 143 144 } // namespace node 145 146 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 147 148 #endif // SRC_NODE_REALM_INL_H_
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2025 MyWebUniversity.com ™