Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2021-08-31 18:17:06 +0300
committerJoyee Cheung <joyeec9h3@gmail.com>2021-09-06 13:12:45 +0300
commitafc77605d27cc63b4d2d091e298bf6a5c9be2544 (patch)
treee41dc8cb4e891b6193f918997403a3317d8ac22a /src
parentb9ed7e554570508082a425b1131407485c3591a8 (diff)
src: register external references of BaseObject for snapshot
PR-URL: https://github.com/nodejs/node/pull/39961 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <midawson@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/base_object-inl.h16
-rw-r--r--src/base_object.h2
-rw-r--r--src/node_external_reference.cc3
3 files changed, 14 insertions, 7 deletions
diff --git a/src/base_object-inl.h b/src/base_object-inl.h
index ad900b6399f..bb1e8d4b46b 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<v8::Value>& args) {
+ DCHECK(args.IsConstructCall());
+ DCHECK_GT(args.This()->InternalFieldCount(), 0);
+ args.This()->SetAlignedPointerInInternalField(BaseObject::kSlot, nullptr);
+}
+
v8::Local<v8::FunctionTemplate>
BaseObject::MakeLazilyInitializedJSTemplate(Environment* env) {
- auto constructor = [](const v8::FunctionCallbackInfo<v8::Value>& args) {
- DCHECK(args.IsConstructCall());
- DCHECK_GT(args.This()->InternalFieldCount(), 0);
- args.This()->SetAlignedPointerInInternalField(BaseObject::kSlot, nullptr);
- };
-
- v8::Local<v8::FunctionTemplate> t = env->NewFunctionTemplate(constructor);
+ v8::Local<v8::FunctionTemplate> 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 ec9d4a69d53..d46a0f21600 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<v8::Value>& args);
static inline BaseObject* FromJSObject(v8::Local<v8::Value> object);
template <typename T>
static inline T* FromJSObject(v8::Local<v8::Value> object);
diff --git a/src/node_external_reference.cc b/src/node_external_reference.cc
index 73e1489865d..94198719b6a 100644
--- a/src/node_external_reference.cc
+++ b/src/node_external_reference.cc
@@ -1,6 +1,7 @@
#include "node_external_reference.h"
#include <cinttypes>
#include <vector>
+#include "base_object-inl.h"
#include "util.h"
namespace node {
@@ -13,6 +14,8 @@ const std::vector<intptr_t>& ExternalReferenceRegistry::external_references() {
}
ExternalReferenceRegistry::ExternalReferenceRegistry() {
+ this->Register(BaseObject::LazilyInitializedJSTemplateConstructor);
+
#define V(modname) _register_external_reference_##modname(this);
EXTERNAL_REFERENCE_BINDING_LIST(V)
#undef V