Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 667d520

Browse filesBrowse files
committed
src: introduce BaseObject base FunctionTemplate
PR-URL: #33772 Backport-PR-URL: #33965 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent b4819db commit 667d520
Copy full SHA for 667d520

File tree

Expand file treeCollapse file tree

13 files changed

+34
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

13 files changed

+34
-0
lines changed
Open diff view settings
Collapse file

‎src/async_wrap.cc‎

Copy file name to clipboardExpand all lines: src/async_wrap.cc
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ Local<FunctionTemplate> AsyncWrap::GetConstructorTemplate(Environment* env) {
498498
if (tmpl.IsEmpty()) {
499499
tmpl = env->NewFunctionTemplate(nullptr);
500500
tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "AsyncWrap"));
501+
tmpl->Inherit(BaseObject::GetConstructorTemplate(env));
501502
env->SetProtoMethod(tmpl, "getAsyncId", AsyncWrap::GetAsyncId);
502503
env->SetProtoMethod(tmpl, "asyncReset", AsyncWrap::AsyncReset);
503504
env->SetProtoMethod(tmpl, "getProviderType", AsyncWrap::GetProviderType);
Collapse file

‎src/base_object-inl.h‎

Copy file name to clipboardExpand all lines: src/base_object-inl.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ BaseObject::MakeLazilyInitializedJSTemplate(Environment* env) {
155155
};
156156

157157
v8::Local<v8::FunctionTemplate> t = env->NewFunctionTemplate(constructor);
158+
t->Inherit(BaseObject::GetConstructorTemplate(env));
158159
t->InstanceTemplate()->SetInternalFieldCount(
159160
BaseObject::kInternalFieldCount);
160161
return t;
Collapse file

‎src/base_object.h‎

Copy file name to clipboardExpand all lines: src/base_object.h
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ class BaseObject : public MemoryRetainer {
9898
// a BaseObjectPtr to this object.
9999
inline void Detach();
100100

101+
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
102+
Environment* env);
103+
101104
protected:
102105
virtual inline void OnGCCollect();
103106

Collapse file

‎src/env.cc‎

Copy file name to clipboardExpand all lines: src/env.cc
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ void Environment::CreateProperties() {
264264
Local<Context> ctx = context();
265265
Local<FunctionTemplate> templ = FunctionTemplate::New(isolate());
266266
templ->InstanceTemplate()->SetInternalFieldCount(1);
267+
templ->Inherit(BaseObject::GetConstructorTemplate(this));
267268
Local<Object> obj = templ->GetFunction(ctx)
268269
.ToLocalChecked()
269270
->NewInstance(ctx)
@@ -1208,4 +1209,14 @@ bool BaseObject::IsRootNode() const {
12081209
return !persistent_handle_.IsWeak();
12091210
}
12101211

1212+
Local<FunctionTemplate> BaseObject::GetConstructorTemplate(Environment* env) {
1213+
Local<FunctionTemplate> tmpl = env->base_object_ctor_template();
1214+
if (tmpl.IsEmpty()) {
1215+
tmpl = env->NewFunctionTemplate(nullptr);
1216+
tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "BaseObject"));
1217+
env->set_base_object_ctor_template(tmpl);
1218+
}
1219+
return tmpl;
1220+
}
1221+
12111222
} // namespace node
Collapse file

‎src/env.h‎

Copy file name to clipboardExpand all lines: src/env.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ constexpr size_t kFsStatsBufferLength =
406406
V(as_callback_data_template, v8::FunctionTemplate) \
407407
V(async_wrap_ctor_template, v8::FunctionTemplate) \
408408
V(async_wrap_object_ctor_template, v8::FunctionTemplate) \
409+
V(base_object_ctor_template, v8::FunctionTemplate) \
409410
V(compiled_fn_entry_template, v8::ObjectTemplate) \
410411
V(dir_instance_template, v8::ObjectTemplate) \
411412
V(fd_constructor_template, v8::ObjectTemplate) \
Collapse file

‎src/module_wrap.cc‎

Copy file name to clipboardExpand all lines: src/module_wrap.cc
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ void ModuleWrap::Initialize(Local<Object> target,
691691
tpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"));
692692
tpl->InstanceTemplate()->SetInternalFieldCount(
693693
ModuleWrap::kInternalFieldCount);
694+
tpl->Inherit(BaseObject::GetConstructorTemplate(env));
694695

695696
env->SetProtoMethod(tpl, "link", Link);
696697
env->SetProtoMethod(tpl, "instantiate", Instantiate);
Collapse file

‎src/node_crypto.cc‎

Copy file name to clipboardExpand all lines: src/node_crypto.cc
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) {
434434
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
435435
t->InstanceTemplate()->SetInternalFieldCount(
436436
SecureContext::kInternalFieldCount);
437+
t->Inherit(BaseObject::GetConstructorTemplate(env));
437438
Local<String> secureContextString =
438439
FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext");
439440
t->SetClassName(secureContextString);
@@ -3208,6 +3209,7 @@ Local<Function> KeyObject::Initialize(Environment* env, Local<Object> target) {
32083209
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
32093210
t->InstanceTemplate()->SetInternalFieldCount(
32103211
KeyObject::kInternalFieldCount);
3212+
t->Inherit(BaseObject::GetConstructorTemplate(env));
32113213

32123214
env->SetProtoMethod(t, "init", Init);
32133215
env->SetProtoMethodNoSideEffect(t, "getSymmetricKeySize",
@@ -3442,6 +3444,7 @@ void CipherBase::Initialize(Environment* env, Local<Object> target) {
34423444

34433445
t->InstanceTemplate()->SetInternalFieldCount(
34443446
CipherBase::kInternalFieldCount);
3447+
t->Inherit(BaseObject::GetConstructorTemplate(env));
34453448

34463449
env->SetProtoMethod(t, "init", Init);
34473450
env->SetProtoMethod(t, "initiv", InitIv);
@@ -4069,6 +4072,7 @@ void Hmac::Initialize(Environment* env, Local<Object> target) {
40694072

40704073
t->InstanceTemplate()->SetInternalFieldCount(
40714074
Hmac::kInternalFieldCount);
4075+
t->Inherit(BaseObject::GetConstructorTemplate(env));
40724076

40734077
env->SetProtoMethod(t, "init", HmacInit);
40744078
env->SetProtoMethod(t, "update", HmacUpdate);
@@ -4195,6 +4199,7 @@ void Hash::Initialize(Environment* env, Local<Object> target) {
41954199

41964200
t->InstanceTemplate()->SetInternalFieldCount(
41974201
Hash::kInternalFieldCount);
4202+
t->Inherit(BaseObject::GetConstructorTemplate(env));
41984203

41994204
env->SetProtoMethod(t, "update", HashUpdate);
42004205
env->SetProtoMethod(t, "digest", HashDigest);
@@ -4467,6 +4472,7 @@ void Sign::Initialize(Environment* env, Local<Object> target) {
44674472

44684473
t->InstanceTemplate()->SetInternalFieldCount(
44694474
SignBase::kInternalFieldCount);
4475+
t->Inherit(BaseObject::GetConstructorTemplate(env));
44704476

44714477
env->SetProtoMethod(t, "init", SignInit);
44724478
env->SetProtoMethod(t, "update", SignUpdate);
@@ -4792,6 +4798,7 @@ void Verify::Initialize(Environment* env, Local<Object> target) {
47924798

47934799
t->InstanceTemplate()->SetInternalFieldCount(
47944800
SignBase::kInternalFieldCount);
4801+
t->Inherit(BaseObject::GetConstructorTemplate(env));
47954802

47964803
env->SetProtoMethod(t, "init", VerifyInit);
47974804
env->SetProtoMethod(t, "update", VerifyUpdate);
@@ -5104,6 +5111,7 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
51045111

51055112
t->InstanceTemplate()->SetInternalFieldCount(
51065113
DiffieHellman::kInternalFieldCount);
5114+
t->Inherit(BaseObject::GetConstructorTemplate(env));
51075115

51085116
env->SetProtoMethod(t, "generateKeys", GenerateKeys);
51095117
env->SetProtoMethod(t, "computeSecret", ComputeSecret);
@@ -5462,6 +5470,7 @@ void ECDH::Initialize(Environment* env, Local<Object> target) {
54625470
HandleScope scope(env->isolate());
54635471

54645472
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
5473+
t->Inherit(BaseObject::GetConstructorTemplate(env));
54655474

54665475
t->InstanceTemplate()->SetInternalFieldCount(ECDH::kInternalFieldCount);
54675476

Collapse file

‎src/node_i18n.cc‎

Copy file name to clipboardExpand all lines: src/node_i18n.cc
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,7 @@ void Initialize(Local<Object> target,
811811
// ConverterObject
812812
{
813813
Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate());
814+
t->Inherit(BaseObject::GetConstructorTemplate(env));
814815
t->InstanceTemplate()->SetInternalFieldCount(
815816
ConverterObject::kInternalFieldCount);
816817
Local<String> converter_string =
Collapse file

‎src/node_perf.cc‎

Copy file name to clipboardExpand all lines: src/node_perf.cc
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ void Initialize(Local<Object> target,
652652
eldh->SetClassName(eldh_classname);
653653
eldh->InstanceTemplate()->SetInternalFieldCount(
654654
ELDHistogram::kInternalFieldCount);
655+
eldh->Inherit(BaseObject::GetConstructorTemplate(env));
655656
env->SetProtoMethod(eldh, "exceeds", ELDHistogramExceeds);
656657
env->SetProtoMethod(eldh, "min", ELDHistogramMin);
657658
env->SetProtoMethod(eldh, "max", ELDHistogramMax);
Collapse file

‎src/node_serdes.cc‎

Copy file name to clipboardExpand all lines: src/node_serdes.cc
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ void Initialize(Local<Object> target,
453453

454454
ser->InstanceTemplate()->SetInternalFieldCount(
455455
SerializerContext::kInternalFieldCount);
456+
ser->Inherit(BaseObject::GetConstructorTemplate(env));
456457

457458
env->SetProtoMethod(ser, "writeHeader", SerializerContext::WriteHeader);
458459
env->SetProtoMethod(ser, "writeValue", SerializerContext::WriteValue);
@@ -480,6 +481,7 @@ void Initialize(Local<Object> target,
480481

481482
des->InstanceTemplate()->SetInternalFieldCount(
482483
DeserializerContext::kInternalFieldCount);
484+
des->Inherit(BaseObject::GetConstructorTemplate(env));
483485

484486
env->SetProtoMethod(des, "readHeader", DeserializerContext::ReadHeader);
485487
env->SetProtoMethod(des, "readValue", DeserializerContext::ReadValue);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.