| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6fdf025 commit a2c1c3e
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -148,15 +148,17 @@ bool BaseObject::IsWeakOrDetached() const { | |||
| 148 | 148 | return pd->wants_weak_jsobj || pd->is_detached; | |
| 149 | 149 | } | |
| 150 | 150 | ||
| 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 | + | ||
| 151 | 158 | v8::Local<v8::FunctionTemplate> | |
| 152 | 159 | BaseObject::MakeLazilyInitializedJSTemplate(Environment* env) { | |
| 153 | - auto constructor = [](const v8::FunctionCallbackInfo<v8::Value>& args) { | ||
| 154 | - DCHECK(args.IsConstructCall()); | ||
| 155 | - DCHECK_GT(args.This()->InternalFieldCount(), 0); | ||
| 156 | - args.This()->SetAlignedPointerInInternalField(BaseObject::kSlot, nullptr); | ||
| 157 | - }; | ||
| 158 | - | ||
| 159 | - v8::Local<v8::FunctionTemplate> t = env->NewFunctionTemplate(constructor); | ||
| 160 | + v8::Local<v8::FunctionTemplate> t = | ||
| 161 | + env->NewFunctionTemplate(LazilyInitializedJSTemplateConstructor); | ||
| 160 | 162 | t->Inherit(BaseObject::GetConstructorTemplate(env)); | |
| 161 | 163 | t->InstanceTemplate()->SetInternalFieldCount( | |
| 162 | 164 | BaseObject::kInternalFieldCount); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,6 +65,8 @@ 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( | ||
| 69 | + const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 68 | 70 | static inline BaseObject* FromJSObject(v8::Local<v8::Value> object); | |
| 69 | 71 | template <typename T> | |
| 70 | 72 | static inline T* FromJSObject(v8::Local<v8::Value> object); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | #include "node_external_reference.h" | |
| 2 | 2 | #include <cinttypes> | |
| 3 | 3 | #include <vector> | |
| 4 | + #include "base_object-inl.h" | ||
| 4 | 5 | #include "util.h" | |
| 5 | 6 | ||
| 6 | 7 | namespace node { | |
@@ -13,6 +14,8 @@ const std::vector<intptr_t>& ExternalReferenceRegistry::external_references() { | |||
| 13 | 14 | } | |
| 14 | 15 | ||
| 15 | 16 | ExternalReferenceRegistry::ExternalReferenceRegistry() { | |
| 17 | + this->Register(BaseObject::LazilyInitializedJSTemplateConstructor); | ||
| 18 | + | ||
| 16 | 19 | #define V(modname) _register_external_reference_##modname(this); | |
| 17 | 20 | EXTERNAL_REFERENCE_BINDING_LIST(V) | |
| 18 | 21 | #undef V | |
| Back | FazBrowse Home | New Git URL |
0 commit comments