diff --git a/src/base_object-inl.h b/src/base_object-inl.h index ad900b6399f149..bb1e8d4b46bce3 100644 --- a/src/base_object-inl.h +++ b/src/base_object-inl.h @@ -148,15 +148,17 @@ bool BaseObject::IsWeakOrDetached() const { return pd->wants_weak_jsobj || pd->is_detached; } +void BaseObject::LazilyInitializedJSTemplateConstructor( + const v8::FunctionCallbackInfo& args) { + DCHECK(args.IsConstructCall()); + DCHECK_GT(args.This()->InternalFieldCount(), 0); + args.This()->SetAlignedPointerInInternalField(BaseObject::kSlot, nullptr); +} + v8::Local BaseObject::MakeLazilyInitializedJSTemplate(Environment* env) { - auto constructor = [](const v8::FunctionCallbackInfo& args) { - DCHECK(args.IsConstructCall()); - DCHECK_GT(args.This()->InternalFieldCount(), 0); - args.This()->SetAlignedPointerInInternalField(BaseObject::kSlot, nullptr); - }; - - v8::Local t = env->NewFunctionTemplate(constructor); + v8::Local t = + env->NewFunctionTemplate(LazilyInitializedJSTemplateConstructor); t->Inherit(BaseObject::GetConstructorTemplate(env)); t->InstanceTemplate()->SetInternalFieldCount( BaseObject::kInternalFieldCount); diff --git a/src/base_object.h b/src/base_object.h index ec9d4a69d537b2..d46a0f216009c6 100644 --- a/src/base_object.h +++ b/src/base_object.h @@ -65,6 +65,8 @@ class BaseObject : public MemoryRetainer { // was also passed to the `BaseObject()` constructor initially. // This may return `nullptr` if the C++ object has not been constructed yet, // e.g. when the JS object used `MakeLazilyInitializedJSTemplate`. + static inline void LazilyInitializedJSTemplateConstructor( + const v8::FunctionCallbackInfo& args); static inline BaseObject* FromJSObject(v8::Local object); template static inline T* FromJSObject(v8::Local object); diff --git a/src/node_external_reference.cc b/src/node_external_reference.cc index 73e1489865d3a4..94198719b6a002 100644 --- a/src/node_external_reference.cc +++ b/src/node_external_reference.cc @@ -1,6 +1,7 @@ #include "node_external_reference.h" #include #include +#include "base_object-inl.h" #include "util.h" namespace node { @@ -13,6 +14,8 @@ const std::vector& ExternalReferenceRegistry::external_references() { } ExternalReferenceRegistry::ExternalReferenceRegistry() { + this->Register(BaseObject::LazilyInitializedJSTemplateConstructor); + #define V(modname) _register_external_reference_##modname(this); EXTERNAL_REFERENCE_BINDING_LIST(V) #undef V