| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 364deea commit 8432d65
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,13 +80,6 @@ inline v8::MaybeLocal<v8::Value> AsyncWrap::MakeCallback( | |||
| 80 | 80 | return MakeCallback(cb_v.As<v8::Function>(), argc, argv); | |
| 81 | 81 | } | |
| 82 | 82 | ||
| 83 | - | ||
| 84 | - // Defined here to avoid a circular dependency with env-inl.h. | ||
| 85 | - inline AsyncHooks::DefaultTriggerAsyncIdScope ::DefaultTriggerAsyncIdScope( | ||
| 86 | - AsyncWrap* async_wrap) | ||
| 87 | - : DefaultTriggerAsyncIdScope(async_wrap->env(), | ||
| 88 | - async_wrap->get_async_id()) {} | ||
| 89 | - | ||
| 90 | 83 | } // namespace node | |
| 91 | 84 | ||
| 92 | 85 | #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,40 +32,6 @@ | |||
| 32 | 32 | ||
| 33 | 33 | namespace node { | |
| 34 | 34 | ||
| 35 | - BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> object) | ||
| 36 | - : persistent_handle_(env->isolate(), object), env_(env) { | ||
| 37 | - CHECK_EQ(false, object.IsEmpty()); | ||
| 38 | - CHECK_GT(object->InternalFieldCount(), 0); | ||
| 39 | - object->SetAlignedPointerInInternalField( | ||
| 40 | - BaseObject::kSlot, | ||
| 41 | - static_cast<void*>(this)); | ||
| 42 | - env->AddCleanupHook(DeleteMe, static_cast<void*>(this)); | ||
| 43 | - env->modify_base_object_count(1); | ||
| 44 | - } | ||
| 45 | - | ||
| 46 | - BaseObject::~BaseObject() { | ||
| 47 | - env()->modify_base_object_count(-1); | ||
| 48 | - env()->RemoveCleanupHook(DeleteMe, static_cast<void*>(this)); | ||
| 49 | - | ||
| 50 | - if (UNLIKELY(has_pointer_data())) { | ||
| 51 | - PointerData* metadata = pointer_data(); | ||
| 52 | - CHECK_EQ(metadata->strong_ptr_count, 0); | ||
| 53 | - metadata->self = nullptr; | ||
| 54 | - if (metadata->weak_ptr_count == 0) | ||
| 55 | - delete metadata; | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - if (persistent_handle_.IsEmpty()) { | ||
| 59 | - // This most likely happened because the weak callback below cleared it. | ||
| 60 | - return; | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - { | ||
| 64 | - v8::HandleScope handle_scope(env()->isolate()); | ||
| 65 | - object()->SetAlignedPointerInInternalField(BaseObject::kSlot, nullptr); | ||
| 66 | - } | ||
| 67 | - } | ||
| 68 | - | ||
| 69 | 35 | void BaseObject::Detach() { | |
| 70 | 36 | CHECK_GT(pointer_data()->strong_ptr_count, 0); | |
| 71 | 37 | pointer_data()->is_detached = true; | |
@@ -107,28 +73,6 @@ T* BaseObject::FromJSObject(v8::Local<v8::Value> object) { | |||
| 107 | 73 | return static_cast<T*>(FromJSObject(object)); | |
| 108 | 74 | } | |
| 109 | 75 | ||
| 110 | - | ||
| 111 | - void BaseObject::MakeWeak() { | ||
| 112 | - if (has_pointer_data()) { | ||
| 113 | - pointer_data()->wants_weak_jsobj = true; | ||
| 114 | - if (pointer_data()->strong_ptr_count > 0) return; | ||
| 115 | - } | ||
| 116 | - | ||
| 117 | - persistent_handle_.SetWeak( | ||
| 118 | - this, | ||
| 119 | - [](const v8::WeakCallbackInfo<BaseObject>& data) { | ||
| 120 | - BaseObject* obj = data.GetParameter(); | ||
| 121 | - // Clear the persistent handle so that ~BaseObject() doesn't attempt | ||
| 122 | - // to mess with internal fields, since the JS object may have | ||
| 123 | - // transitioned into an invalid state. | ||
| 124 | - // Refs: https://github.com/nodejs/node/issues/18897 | ||
| 125 | - obj->persistent_handle_.Reset(); | ||
| 126 | - CHECK_IMPLIES(obj->has_pointer_data(), | ||
| 127 | - obj->pointer_data()->strong_ptr_count == 0); | ||
| 128 | - obj->OnGCCollect(); | ||
| 129 | - }, v8::WeakCallbackType::kParameter); | ||
| 130 | - } | ||
| 131 | - | ||
| 132 | 76 | void BaseObject::OnGCCollect() { | |
| 133 | 77 | delete this; | |
| 134 | 78 | } | |
@@ -148,23 +92,6 @@ bool BaseObject::IsWeakOrDetached() const { | |||
| 148 | 92 | return pd->wants_weak_jsobj || pd->is_detached; | |
| 149 | 93 | } | |
| 150 | 94 | ||
| 151 | - void BaseObject::LazilyInitializedJSTemplateConstructor( | ||
| 152 | - const v8::FunctionCallbackInfo<v8::Value>& args) { | ||
| 153 | - DCHECK(args.IsConstructCall()); | ||
| 154 | - DCHECK_GT(args.This()->InternalFieldCount(), 0); | ||
| 155 | - args.This()->SetAlignedPointerInInternalField(BaseObject::kSlot, nullptr); | ||
| 156 | - } | ||
| 157 | - | ||
| 158 | - v8::Local<v8::FunctionTemplate> | ||
| 159 | - BaseObject::MakeLazilyInitializedJSTemplate(Environment* env) { | ||
| 160 | - v8::Local<v8::FunctionTemplate> t = | ||
| 161 | - env->NewFunctionTemplate(LazilyInitializedJSTemplateConstructor); | ||
| 162 | - t->Inherit(BaseObject::GetConstructorTemplate(env)); | ||
| 163 | - t->InstanceTemplate()->SetInternalFieldCount( | ||
| 164 | - BaseObject::kInternalFieldCount); | ||
| 165 | - return t; | ||
| 166 | - } | ||
| 167 | - | ||
| 168 | 95 | template <int Field> | |
| 169 | 96 | void BaseObject::InternalFieldGet( | |
| 170 | 97 | v8::Local<v8::String> property, | |
@@ -185,37 +112,6 @@ bool BaseObject::has_pointer_data() const { | |||
| 185 | 112 | return pointer_data_ != nullptr; | |
| 186 | 113 | } | |
| 187 | 114 | ||
| 188 | - BaseObject::PointerData* BaseObject::pointer_data() { | ||
| 189 | - if (!has_pointer_data()) { | ||
| 190 | - PointerData* metadata = new PointerData(); | ||
| 191 | - metadata->wants_weak_jsobj = persistent_handle_.IsWeak(); | ||
| 192 | - metadata->self = this; | ||
| 193 | - pointer_data_ = metadata; | ||
| 194 | - } | ||
| 195 | - CHECK(has_pointer_data()); | ||
| 196 | - return pointer_data_; | ||
| 197 | - } | ||
| 198 | - | ||
| 199 | - void BaseObject::decrease_refcount() { | ||
| 200 | - CHECK(has_pointer_data()); | ||
| 201 | - PointerData* metadata = pointer_data(); | ||
| 202 | - CHECK_GT(metadata->strong_ptr_count, 0); | ||
| 203 | - unsigned int new_refcount = --metadata->strong_ptr_count; | ||
| 204 | - if (new_refcount == 0) { | ||
| 205 | - if (metadata->is_detached) { | ||
| 206 | - OnGCCollect(); | ||
| 207 | - } else if (metadata->wants_weak_jsobj && !persistent_handle_.IsEmpty()) { | ||
| 208 | - MakeWeak(); | ||
| 209 | - } | ||
| 210 | - } | ||
| 211 | - } | ||
| 212 | - | ||
| 213 | - void BaseObject::increase_refcount() { | ||
| 214 | - unsigned int prev_refcount = pointer_data()->strong_ptr_count++; | ||
| 215 | - if (prev_refcount == 0 && !persistent_handle_.IsEmpty()) | ||
| 216 | - persistent_handle_.ClearWeak(); | ||
| 217 | - } | ||
| 218 | - | ||
| 219 | 115 | template <typename T, bool kIsWeak> | |
| 220 | 116 | BaseObject::PointerData* | |
| 221 | 117 | BaseObjectPtrImpl<T, kIsWeak>::pointer_data() const { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,8 +44,8 @@ class BaseObject : public MemoryRetainer { | |||
| 44 | 44 | ||
| 45 | 45 | // Associates this object with `object`. It uses the 0th internal field for | |
| 46 | 46 | // that, and in particular aborts if there is no such field. | |
| 47 | - inline BaseObject(Environment* env, v8::Local<v8::Object> object); | ||
| 48 | - inline ~BaseObject() override; | ||
| 47 | + BaseObject(Environment* env, v8::Local<v8::Object> object); | ||
| 48 | + ~BaseObject() override; | ||
| 49 | 49 | ||
| 50 | 50 | BaseObject() = delete; | |
| 51 | 51 | ||
@@ -65,7 +65,7 @@ class BaseObject : public MemoryRetainer { | |||
| 65 | 65 | // was also passed to the `BaseObject()` constructor initially. | |
| 66 | 66 | // This may return `nullptr` if the C++ object has not been constructed yet, | |
| 67 | 67 | // e.g. when the JS object used `MakeLazilyInitializedJSTemplate`. | |
| 68 | - static inline void LazilyInitializedJSTemplateConstructor( | ||
| 68 | + static void LazilyInitializedJSTemplateConstructor( | ||
| 69 | 69 | const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 70 | 70 | static inline BaseObject* FromJSObject(v8::Local<v8::Value> object); | |
| 71 | 71 | template <typename T> | |
@@ -74,7 +74,7 @@ class BaseObject : public MemoryRetainer { | |||
| 74 | 74 | // Make the `v8::Global` a weak reference and, `delete` this object once | |
| 75 | 75 | // the JS object has been garbage collected and there are no (strong) | |
| 76 | 76 | // BaseObjectPtr references to it. | |
| 77 | - inline void MakeWeak(); | ||
| 77 | + void MakeWeak(); | ||
| 78 | 78 | ||
| 79 | 79 | // Undo `MakeWeak()`, i.e. turn this into a strong reference that is a GC | |
| 80 | 80 | // root and will not be touched by the garbage collector. | |
@@ -88,7 +88,7 @@ class BaseObject : public MemoryRetainer { | |||
| 88 | 88 | // Utility to create a FunctionTemplate with one internal field (used for | |
| 89 | 89 | // the `BaseObject*` pointer) and a constructor that initializes that field | |
| 90 | 90 | // to `nullptr`. | |
| 91 | - static inline v8::Local<v8::FunctionTemplate> MakeLazilyInitializedJSTemplate( | ||
| 91 | + static v8::Local<v8::FunctionTemplate> MakeLazilyInitializedJSTemplate( | ||
| 92 | 92 | Environment* env); | |
| 93 | 93 | ||
| 94 | 94 | // Setter/Getter pair for internal fields that can be passed to SetAccessor. | |
@@ -202,11 +202,11 @@ class BaseObject : public MemoryRetainer { | |||
| 202 | 202 | inline bool has_pointer_data() const; | |
| 203 | 203 | // This creates a PointerData struct if none was associated with this | |
| 204 | 204 | // BaseObject before. | |
| 205 | - inline PointerData* pointer_data(); | ||
| 205 | + PointerData* pointer_data(); | ||
| 206 | 206 | ||
| 207 | 207 | // Functions that adjust the strong pointer count. | |
| 208 | - inline void decrease_refcount(); | ||
| 209 | - inline void increase_refcount(); | ||
| 208 | + void decrease_refcount(); | ||
| 209 | + void increase_refcount(); | ||
| 210 | 210 | ||
| 211 | 211 | Environment* env_; | |
| 212 | 212 | PointerData* pointer_data_ = nullptr; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments