Skip to content

Commit a2c1c3e

Browse files
joyeecheungBethGriggs
authored andcommittedSep 21, 2021
src: register external references of BaseObject for snapshot
PR-URL: #39961 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <midawson@redhat.com>
1 parent 6fdf025 commit a2c1c3e

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed
 

‎src/base_object-inl.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,17 @@ bool BaseObject::IsWeakOrDetached() const {
148148
return pd->wants_weak_jsobj || pd->is_detached;
149149
}
150150

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+
151158
v8::Local<v8::FunctionTemplate>
152159
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);
160162
t->Inherit(BaseObject::GetConstructorTemplate(env));
161163
t->InstanceTemplate()->SetInternalFieldCount(
162164
BaseObject::kInternalFieldCount);

‎src/base_object.h

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class BaseObject : public MemoryRetainer {
6565
// was also passed to the `BaseObject()` constructor initially.
6666
// This may return `nullptr` if the C++ object has not been constructed yet,
6767
// e.g. when the JS object used `MakeLazilyInitializedJSTemplate`.
68+
static inline void LazilyInitializedJSTemplateConstructor(
69+
const v8::FunctionCallbackInfo<v8::Value>& args);
6870
static inline BaseObject* FromJSObject(v8::Local<v8::Value> object);
6971
template <typename T>
7072
static inline T* FromJSObject(v8::Local<v8::Value> object);

‎src/node_external_reference.cc

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "node_external_reference.h"
22
#include <cinttypes>
33
#include <vector>
4+
#include "base_object-inl.h"
45
#include "util.h"
56

67
namespace node {
@@ -13,6 +14,8 @@ const std::vector<intptr_t>& ExternalReferenceRegistry::external_references() {
1314
}
1415

1516
ExternalReferenceRegistry::ExternalReferenceRegistry() {
17+
this->Register(BaseObject::LazilyInitializedJSTemplateConstructor);
18+
1619
#define V(modname) _register_external_reference_##modname(this);
1720
EXTERNAL_REFERENCE_BINDING_LIST(V)
1821
#undef V

0 commit comments

Comments
 (0)
Please sign in to comment.