mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
src: introduce BaseObject base FunctionTemplate
PR-URL: https://github.com/nodejs/node/pull/33772 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
14 files changed
+38
-1
No files matched your search
@@ -557,6 +557,7 @@ Local<FunctionTemplate> AsyncWrap::GetConstructorTemplate(Environment* env) {
|
|||||||
if (tmpl.IsEmpty()) {
|
if (tmpl.IsEmpty()) {
|
||||||
tmpl = env->NewFunctionTemplate(nullptr);
|
tmpl = env->NewFunctionTemplate(nullptr);
|
||||||
tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "AsyncWrap"));
|
tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "AsyncWrap"));
|
||||||
|
tmpl->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
env->SetProtoMethod(tmpl, "getAsyncId", AsyncWrap::GetAsyncId);
|
env->SetProtoMethod(tmpl, "getAsyncId", AsyncWrap::GetAsyncId);
|
||||||
env->SetProtoMethod(tmpl, "asyncReset", AsyncWrap::AsyncReset);
|
env->SetProtoMethod(tmpl, "asyncReset", AsyncWrap::AsyncReset);
|
||||||
env->SetProtoMethod(tmpl, "getProviderType", AsyncWrap::GetProviderType);
|
env->SetProtoMethod(tmpl, "getProviderType", AsyncWrap::GetProviderType);
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ BaseObject::MakeLazilyInitializedJSTemplate(Environment* env) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
v8::Local<v8::FunctionTemplate> t = env->NewFunctionTemplate(constructor);
|
v8::Local<v8::FunctionTemplate> t = env->NewFunctionTemplate(constructor);
|
||||||
|
t->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
t->InstanceTemplate()->SetInternalFieldCount(
|
t->InstanceTemplate()->SetInternalFieldCount(
|
||||||
BaseObject::kInternalFieldCount);
|
BaseObject::kInternalFieldCount);
|
||||||
return t;
|
return t;
|
||||||
|
|||||||
@@ -98,6 +98,9 @@ class BaseObject : public MemoryRetainer {
|
|||||||
// a BaseObjectPtr to this object.
|
// a BaseObjectPtr to this object.
|
||||||
inline void Detach();
|
inline void Detach();
|
||||||
|
|
||||||
|
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
|
||||||
|
Environment* env);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual inline void OnGCCollect();
|
virtual inline void OnGCCollect();
|
||||||
|
|
||||||
|
|||||||
+11
@@ -269,6 +269,7 @@ void Environment::CreateProperties() {
|
|||||||
Local<FunctionTemplate> templ = FunctionTemplate::New(isolate());
|
Local<FunctionTemplate> templ = FunctionTemplate::New(isolate());
|
||||||
templ->InstanceTemplate()->SetInternalFieldCount(
|
templ->InstanceTemplate()->SetInternalFieldCount(
|
||||||
BaseObject::kInternalFieldCount);
|
BaseObject::kInternalFieldCount);
|
||||||
|
templ->Inherit(BaseObject::GetConstructorTemplate(this));
|
||||||
|
|
||||||
set_binding_data_ctor_template(templ);
|
set_binding_data_ctor_template(templ);
|
||||||
}
|
}
|
||||||
@@ -1112,4 +1113,14 @@ bool BaseObject::IsRootNode() const {
|
|||||||
return !persistent_handle_.IsWeak();
|
return !persistent_handle_.IsWeak();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Local<FunctionTemplate> BaseObject::GetConstructorTemplate(Environment* env) {
|
||||||
|
Local<FunctionTemplate> tmpl = env->base_object_ctor_template();
|
||||||
|
if (tmpl.IsEmpty()) {
|
||||||
|
tmpl = env->NewFunctionTemplate(nullptr);
|
||||||
|
tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "BaseObject"));
|
||||||
|
env->set_base_object_ctor_template(tmpl);
|
||||||
|
}
|
||||||
|
return tmpl;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace node
|
} // namespace node
|
||||||
@@ -395,6 +395,7 @@ constexpr size_t kFsStatsBufferLength =
|
|||||||
#define ENVIRONMENT_STRONG_PERSISTENT_TEMPLATES(V) \
|
#define ENVIRONMENT_STRONG_PERSISTENT_TEMPLATES(V) \
|
||||||
V(async_wrap_ctor_template, v8::FunctionTemplate) \
|
V(async_wrap_ctor_template, v8::FunctionTemplate) \
|
||||||
V(async_wrap_object_ctor_template, v8::FunctionTemplate) \
|
V(async_wrap_object_ctor_template, v8::FunctionTemplate) \
|
||||||
|
V(base_object_ctor_template, v8::FunctionTemplate) \
|
||||||
V(binding_data_ctor_template, v8::FunctionTemplate) \
|
V(binding_data_ctor_template, v8::FunctionTemplate) \
|
||||||
V(compiled_fn_entry_template, v8::ObjectTemplate) \
|
V(compiled_fn_entry_template, v8::ObjectTemplate) \
|
||||||
V(dir_instance_template, v8::ObjectTemplate) \
|
V(dir_instance_template, v8::ObjectTemplate) \
|
||||||
|
|||||||
@@ -699,6 +699,7 @@ void ModuleWrap::Initialize(Local<Object> target,
|
|||||||
tpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"));
|
tpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"));
|
||||||
tpl->InstanceTemplate()->SetInternalFieldCount(
|
tpl->InstanceTemplate()->SetInternalFieldCount(
|
||||||
ModuleWrap::kInternalFieldCount);
|
ModuleWrap::kInternalFieldCount);
|
||||||
|
tpl->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
|
|
||||||
env->SetProtoMethod(tpl, "link", Link);
|
env->SetProtoMethod(tpl, "link", Link);
|
||||||
env->SetProtoMethod(tpl, "instantiate", Instantiate);
|
env->SetProtoMethod(tpl, "instantiate", Instantiate);
|
||||||
|
|||||||
@@ -455,6 +455,7 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) {
|
|||||||
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
|
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
|
||||||
t->InstanceTemplate()->SetInternalFieldCount(
|
t->InstanceTemplate()->SetInternalFieldCount(
|
||||||
SecureContext::kInternalFieldCount);
|
SecureContext::kInternalFieldCount);
|
||||||
|
t->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
Local<String> secureContextString =
|
Local<String> secureContextString =
|
||||||
FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext");
|
FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext");
|
||||||
t->SetClassName(secureContextString);
|
t->SetClassName(secureContextString);
|
||||||
@@ -3246,6 +3247,7 @@ Local<Function> KeyObject::Initialize(Environment* env, Local<Object> target) {
|
|||||||
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
|
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
|
||||||
t->InstanceTemplate()->SetInternalFieldCount(
|
t->InstanceTemplate()->SetInternalFieldCount(
|
||||||
KeyObject::kInternalFieldCount);
|
KeyObject::kInternalFieldCount);
|
||||||
|
t->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
|
|
||||||
env->SetProtoMethod(t, "init", Init);
|
env->SetProtoMethod(t, "init", Init);
|
||||||
env->SetProtoMethodNoSideEffect(t, "getSymmetricKeySize",
|
env->SetProtoMethodNoSideEffect(t, "getSymmetricKeySize",
|
||||||
@@ -3480,6 +3482,7 @@ void CipherBase::Initialize(Environment* env, Local<Object> target) {
|
|||||||
|
|
||||||
t->InstanceTemplate()->SetInternalFieldCount(
|
t->InstanceTemplate()->SetInternalFieldCount(
|
||||||
CipherBase::kInternalFieldCount);
|
CipherBase::kInternalFieldCount);
|
||||||
|
t->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
|
|
||||||
env->SetProtoMethod(t, "init", Init);
|
env->SetProtoMethod(t, "init", Init);
|
||||||
env->SetProtoMethod(t, "initiv", InitIv);
|
env->SetProtoMethod(t, "initiv", InitIv);
|
||||||
@@ -4095,6 +4098,7 @@ void Hmac::Initialize(Environment* env, Local<Object> target) {
|
|||||||
|
|
||||||
t->InstanceTemplate()->SetInternalFieldCount(
|
t->InstanceTemplate()->SetInternalFieldCount(
|
||||||
Hmac::kInternalFieldCount);
|
Hmac::kInternalFieldCount);
|
||||||
|
t->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
|
|
||||||
env->SetProtoMethod(t, "init", HmacInit);
|
env->SetProtoMethod(t, "init", HmacInit);
|
||||||
env->SetProtoMethod(t, "update", HmacUpdate);
|
env->SetProtoMethod(t, "update", HmacUpdate);
|
||||||
@@ -4207,6 +4211,7 @@ void Hash::Initialize(Environment* env, Local<Object> target) {
|
|||||||
|
|
||||||
t->InstanceTemplate()->SetInternalFieldCount(
|
t->InstanceTemplate()->SetInternalFieldCount(
|
||||||
Hash::kInternalFieldCount);
|
Hash::kInternalFieldCount);
|
||||||
|
t->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
|
|
||||||
env->SetProtoMethod(t, "update", HashUpdate);
|
env->SetProtoMethod(t, "update", HashUpdate);
|
||||||
env->SetProtoMethod(t, "digest", HashDigest);
|
env->SetProtoMethod(t, "digest", HashDigest);
|
||||||
@@ -4463,6 +4468,7 @@ void Sign::Initialize(Environment* env, Local<Object> target) {
|
|||||||
|
|
||||||
t->InstanceTemplate()->SetInternalFieldCount(
|
t->InstanceTemplate()->SetInternalFieldCount(
|
||||||
SignBase::kInternalFieldCount);
|
SignBase::kInternalFieldCount);
|
||||||
|
t->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
|
|
||||||
env->SetProtoMethod(t, "init", SignInit);
|
env->SetProtoMethod(t, "init", SignInit);
|
||||||
env->SetProtoMethod(t, "update", SignUpdate);
|
env->SetProtoMethod(t, "update", SignUpdate);
|
||||||
@@ -4785,6 +4791,7 @@ void Verify::Initialize(Environment* env, Local<Object> target) {
|
|||||||
|
|
||||||
t->InstanceTemplate()->SetInternalFieldCount(
|
t->InstanceTemplate()->SetInternalFieldCount(
|
||||||
SignBase::kInternalFieldCount);
|
SignBase::kInternalFieldCount);
|
||||||
|
t->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
|
|
||||||
env->SetProtoMethod(t, "init", VerifyInit);
|
env->SetProtoMethod(t, "init", VerifyInit);
|
||||||
env->SetProtoMethod(t, "update", VerifyUpdate);
|
env->SetProtoMethod(t, "update", VerifyUpdate);
|
||||||
@@ -5095,6 +5102,7 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
|
|||||||
|
|
||||||
t->InstanceTemplate()->SetInternalFieldCount(
|
t->InstanceTemplate()->SetInternalFieldCount(
|
||||||
DiffieHellman::kInternalFieldCount);
|
DiffieHellman::kInternalFieldCount);
|
||||||
|
t->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
|
|
||||||
env->SetProtoMethod(t, "generateKeys", GenerateKeys);
|
env->SetProtoMethod(t, "generateKeys", GenerateKeys);
|
||||||
env->SetProtoMethod(t, "computeSecret", ComputeSecret);
|
env->SetProtoMethod(t, "computeSecret", ComputeSecret);
|
||||||
@@ -5454,6 +5462,7 @@ void ECDH::Initialize(Environment* env, Local<Object> target) {
|
|||||||
HandleScope scope(env->isolate());
|
HandleScope scope(env->isolate());
|
||||||
|
|
||||||
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
|
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
|
||||||
|
t->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
|
|
||||||
t->InstanceTemplate()->SetInternalFieldCount(ECDH::kInternalFieldCount);
|
t->InstanceTemplate()->SetInternalFieldCount(ECDH::kInternalFieldCount);
|
||||||
|
|
||||||
|
|||||||
@@ -811,6 +811,7 @@ void Initialize(Local<Object> target,
|
|||||||
// ConverterObject
|
// ConverterObject
|
||||||
{
|
{
|
||||||
Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate());
|
Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate());
|
||||||
|
t->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
t->InstanceTemplate()->SetInternalFieldCount(
|
t->InstanceTemplate()->SetInternalFieldCount(
|
||||||
ConverterObject::kInternalFieldCount);
|
ConverterObject::kInternalFieldCount);
|
||||||
Local<String> converter_string =
|
Local<String> converter_string =
|
||||||
|
|||||||
@@ -644,6 +644,7 @@ void Initialize(Local<Object> target,
|
|||||||
eldh->SetClassName(eldh_classname);
|
eldh->SetClassName(eldh_classname);
|
||||||
eldh->InstanceTemplate()->SetInternalFieldCount(
|
eldh->InstanceTemplate()->SetInternalFieldCount(
|
||||||
ELDHistogram::kInternalFieldCount);
|
ELDHistogram::kInternalFieldCount);
|
||||||
|
eldh->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
env->SetProtoMethod(eldh, "exceeds", ELDHistogramExceeds);
|
env->SetProtoMethod(eldh, "exceeds", ELDHistogramExceeds);
|
||||||
env->SetProtoMethod(eldh, "min", ELDHistogramMin);
|
env->SetProtoMethod(eldh, "min", ELDHistogramMin);
|
||||||
env->SetProtoMethod(eldh, "max", ELDHistogramMax);
|
env->SetProtoMethod(eldh, "max", ELDHistogramMax);
|
||||||
|
|||||||
@@ -426,7 +426,10 @@ static void ReallyExit(const FunctionCallbackInfo<Value>& args) {
|
|||||||
class FastHrtime : public BaseObject {
|
class FastHrtime : public BaseObject {
|
||||||
public:
|
public:
|
||||||
static Local<Object> New(Environment* env) {
|
static Local<Object> New(Environment* env) {
|
||||||
Local<v8::ObjectTemplate> otmpl = v8::ObjectTemplate::New(env->isolate());
|
Local<v8::FunctionTemplate> ctor =
|
||||||
|
v8::FunctionTemplate::New(env->isolate());
|
||||||
|
ctor->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
|
Local<v8::ObjectTemplate> otmpl = ctor->InstanceTemplate();
|
||||||
otmpl->SetInternalFieldCount(FastHrtime::kInternalFieldCount);
|
otmpl->SetInternalFieldCount(FastHrtime::kInternalFieldCount);
|
||||||
|
|
||||||
auto create_func = [env](auto fast_func, auto slow_func) {
|
auto create_func = [env](auto fast_func, auto slow_func) {
|
||||||
|
|||||||
@@ -451,6 +451,7 @@ void Initialize(Local<Object> target,
|
|||||||
|
|
||||||
ser->InstanceTemplate()->SetInternalFieldCount(
|
ser->InstanceTemplate()->SetInternalFieldCount(
|
||||||
SerializerContext::kInternalFieldCount);
|
SerializerContext::kInternalFieldCount);
|
||||||
|
ser->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
|
|
||||||
env->SetProtoMethod(ser, "writeHeader", SerializerContext::WriteHeader);
|
env->SetProtoMethod(ser, "writeHeader", SerializerContext::WriteHeader);
|
||||||
env->SetProtoMethod(ser, "writeValue", SerializerContext::WriteValue);
|
env->SetProtoMethod(ser, "writeValue", SerializerContext::WriteValue);
|
||||||
@@ -478,6 +479,7 @@ void Initialize(Local<Object> target,
|
|||||||
|
|
||||||
des->InstanceTemplate()->SetInternalFieldCount(
|
des->InstanceTemplate()->SetInternalFieldCount(
|
||||||
DeserializerContext::kInternalFieldCount);
|
DeserializerContext::kInternalFieldCount);
|
||||||
|
des->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
|
|
||||||
env->SetProtoMethod(des, "readHeader", DeserializerContext::ReadHeader);
|
env->SetProtoMethod(des, "readHeader", DeserializerContext::ReadHeader);
|
||||||
env->SetProtoMethod(des, "readValue", DeserializerContext::ReadValue);
|
env->SetProtoMethod(des, "readValue", DeserializerContext::ReadValue);
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ void NodeCategorySet::Initialize(Local<Object> target,
|
|||||||
env->NewFunctionTemplate(NodeCategorySet::New);
|
env->NewFunctionTemplate(NodeCategorySet::New);
|
||||||
category_set->InstanceTemplate()->SetInternalFieldCount(
|
category_set->InstanceTemplate()->SetInternalFieldCount(
|
||||||
NodeCategorySet::kInternalFieldCount);
|
NodeCategorySet::kInternalFieldCount);
|
||||||
|
category_set->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
env->SetProtoMethod(category_set, "enable", NodeCategorySet::Enable);
|
env->SetProtoMethod(category_set, "enable", NodeCategorySet::Enable);
|
||||||
env->SetProtoMethod(category_set, "disable", NodeCategorySet::Disable);
|
env->SetProtoMethod(category_set, "disable", NodeCategorySet::Disable);
|
||||||
|
|
||||||
|
|||||||
@@ -325,6 +325,7 @@ void Initialize(Local<Object> target,
|
|||||||
weak_ref->InstanceTemplate()->SetInternalFieldCount(
|
weak_ref->InstanceTemplate()->SetInternalFieldCount(
|
||||||
WeakReference::kInternalFieldCount);
|
WeakReference::kInternalFieldCount);
|
||||||
weak_ref->SetClassName(weak_ref_string);
|
weak_ref->SetClassName(weak_ref_string);
|
||||||
|
weak_ref->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
env->SetProtoMethod(weak_ref, "get", WeakReference::Get);
|
env->SetProtoMethod(weak_ref, "get", WeakReference::Get);
|
||||||
env->SetProtoMethod(weak_ref, "incRef", WeakReference::IncRef);
|
env->SetProtoMethod(weak_ref, "incRef", WeakReference::IncRef);
|
||||||
env->SetProtoMethod(weak_ref, "decRef", WeakReference::DecRef);
|
env->SetProtoMethod(weak_ref, "decRef", WeakReference::DecRef);
|
||||||
|
|||||||
@@ -1679,6 +1679,7 @@ static void Initialize(Local<Object> target,
|
|||||||
auto wasi_wrap_string = FIXED_ONE_BYTE_STRING(env->isolate(), "WASI");
|
auto wasi_wrap_string = FIXED_ONE_BYTE_STRING(env->isolate(), "WASI");
|
||||||
tmpl->InstanceTemplate()->SetInternalFieldCount(WASI::kInternalFieldCount);
|
tmpl->InstanceTemplate()->SetInternalFieldCount(WASI::kInternalFieldCount);
|
||||||
tmpl->SetClassName(wasi_wrap_string);
|
tmpl->SetClassName(wasi_wrap_string);
|
||||||
|
tmpl->Inherit(BaseObject::GetConstructorTemplate(env));
|
||||||
|
|
||||||
env->SetProtoMethod(tmpl, "args_get", WASI::ArgsGet);
|
env->SetProtoMethod(tmpl, "args_get", WASI::ArgsGet);
|
||||||
env->SetProtoMethod(tmpl, "args_sizes_get", WASI::ArgsSizesGet);
|
env->SetProtoMethod(tmpl, "args_sizes_get", WASI::ArgsSizesGet);
|
||||||
|
|||||||
Reference in new issue
Block a user