From 34de704b3c06a2c3d8d90fc8076e385bcf479153 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 22 Mar 2023 15:50:57 +0100 Subject: [PATCH 1/2] src: use the internal field to determine if an object is a BaseObject Instead of storing the function template of BaseObject for checking if an object is BaseObject by calling HasInstance, simply checks the first internal field of the object, which is always set in the BaseObject constructor. This is simpler and faster (there is now no need to iterate over the inheritance for the check). --- src/async_wrap.cc | 1 - src/base_object-inl.h | 15 +++++++++------ src/base_object.cc | 13 ------------- src/base_object.h | 1 + src/crypto/crypto_cipher.cc | 4 +--- src/crypto/crypto_context.cc | 1 - src/crypto/crypto_dh.cc | 1 - src/crypto/crypto_ec.cc | 1 - src/crypto/crypto_hash.cc | 4 +--- src/crypto/crypto_hmac.cc | 4 +--- src/crypto/crypto_keys.cc | 2 -- src/crypto/crypto_sig.cc | 8 ++------ src/crypto/crypto_x509.cc | 1 - src/env.cc | 1 - src/env_properties.h | 1 - src/histogram.cc | 1 - src/module_wrap.cc | 1 - src/node_binding.cc | 1 - src/node_blob.cc | 2 -- src/node_i18n.cc | 1 - src/node_messaging.cc | 15 ++++++++------- src/node_serdes.cc | 2 -- src/node_snapshotable.cc | 13 +------------ src/node_sockaddr.cc | 2 -- src/node_trace_events.cc | 1 - src/node_util.cc | 1 - src/node_wasi.cc | 1 - src/node_wasm_web_api.cc | 1 - 28 files changed, 24 insertions(+), 76 deletions(-) diff --git a/src/async_wrap.cc b/src/async_wrap.cc index e70011f0b7ba..aac2f3c911b0 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -342,7 +342,6 @@ Local AsyncWrap::GetConstructorTemplate( tmpl = NewFunctionTemplate(isolate, nullptr); tmpl->SetClassName( FIXED_ONE_BYTE_STRING(isolate_data->isolate(), "AsyncWrap")); - tmpl->Inherit(BaseObject::GetConstructorTemplate(isolate_data)); SetProtoMethod(isolate, tmpl, "getAsyncId", AsyncWrap::GetAsyncId); SetProtoMethod(isolate, tmpl, "asyncReset", AsyncWrap::AsyncReset); SetProtoMethod( diff --git a/src/base_object-inl.h b/src/base_object-inl.h index f003f1390b86..c8a455d5ecc7 100644 --- a/src/base_object-inl.h +++ b/src/base_object-inl.h @@ -38,12 +38,6 @@ BaseObject::BaseObject(Environment* env, v8::Local object) // while allowing to create a BaseObject in a vm context. } -// static -v8::Local BaseObject::GetConstructorTemplate( - Environment* env) { - return BaseObject::GetConstructorTemplate(env->isolate_data()); -} - void BaseObject::Detach() { CHECK_GT(pointer_data()->strong_ptr_count, 0); pointer_data()->is_detached = true; @@ -76,6 +70,15 @@ Realm* BaseObject::realm() const { return realm_; } +bool BaseObject::IsBaseObject(v8::Local obj) { + if (obj->InternalFieldCount() < BaseObject::kInternalFieldCount) { + return false; + } + void* ptr = + obj->GetAlignedPointerFromInternalField(BaseObject::kEmbedderType); + return ptr == &kNodeEmbedderId; +} + void BaseObject::TagNodeObject(v8::Local object) { DCHECK_GE(object->InternalFieldCount(), BaseObject::kInternalFieldCount); object->SetAlignedPointerInInternalField(BaseObject::kEmbedderType, diff --git a/src/base_object.cc b/src/base_object.cc index d0444573c85a..ed0fafe74d43 100644 --- a/src/base_object.cc +++ b/src/base_object.cc @@ -89,7 +89,6 @@ Local BaseObject::MakeLazilyInitializedJSTemplate( IsolateData* isolate_data) { Local t = NewFunctionTemplate( isolate_data->isolate(), LazilyInitializedJSTemplateConstructor); - t->Inherit(BaseObject::GetConstructorTemplate(isolate_data)); t->InstanceTemplate()->SetInternalFieldCount(BaseObject::kInternalFieldCount); return t; } @@ -145,18 +144,6 @@ bool BaseObject::IsRootNode() const { return !persistent_handle_.IsWeak(); } -Local BaseObject::GetConstructorTemplate( - IsolateData* isolate_data) { - Local tmpl = isolate_data->base_object_ctor_template(); - if (tmpl.IsEmpty()) { - tmpl = NewFunctionTemplate(isolate_data->isolate(), nullptr); - tmpl->SetClassName( - FIXED_ONE_BYTE_STRING(isolate_data->isolate(), "BaseObject")); - isolate_data->set_base_object_ctor_template(tmpl); - } - return tmpl; -} - bool BaseObject::IsNotIndicativeOfMemoryLeakAtExit() const { return IsWeakOrDetached(); } diff --git a/src/base_object.h b/src/base_object.h index 4ac644a034f4..37551473a847 100644 --- a/src/base_object.h +++ b/src/base_object.h @@ -76,6 +76,7 @@ class BaseObject : public MemoryRetainer { // e.g. when the JS object used `MakeLazilyInitializedJSTemplate`. static inline void SetInternalFields(v8::Local object, void* slot); + static inline bool IsBaseObject(v8::Local object); static inline void TagNodeObject(v8::Local object); static void LazilyInitializedJSTemplateConstructor( const v8::FunctionCallbackInfo& args); diff --git a/src/crypto/crypto_cipher.cc b/src/crypto/crypto_cipher.cc index 2685f5ea0bea..2e6e02d229b6 100644 --- a/src/crypto/crypto_cipher.cc +++ b/src/crypto/crypto_cipher.cc @@ -277,9 +277,7 @@ void CipherBase::Initialize(Environment* env, Local target) { Local t = NewFunctionTemplate(isolate, New); - t->InstanceTemplate()->SetInternalFieldCount( - CipherBase::kInternalFieldCount); - t->Inherit(BaseObject::GetConstructorTemplate(env)); + t->InstanceTemplate()->SetInternalFieldCount(CipherBase::kInternalFieldCount); SetProtoMethod(isolate, t, "init", Init); SetProtoMethod(isolate, t, "initiv", InitIv); diff --git a/src/crypto/crypto_context.cc b/src/crypto/crypto_context.cc index cb03cd764390..dafea2cf4af6 100644 --- a/src/crypto/crypto_context.cc +++ b/src/crypto/crypto_context.cc @@ -268,7 +268,6 @@ Local SecureContext::GetConstructorTemplate( tmpl = NewFunctionTemplate(isolate, New); tmpl->InstanceTemplate()->SetInternalFieldCount( SecureContext::kInternalFieldCount); - tmpl->Inherit(BaseObject::GetConstructorTemplate(env)); tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext")); SetProtoMethod(isolate, tmpl, "init", Init); diff --git a/src/crypto/crypto_dh.cc b/src/crypto/crypto_dh.cc index dd69323b8007..408d6be2a9cf 100644 --- a/src/crypto/crypto_dh.cc +++ b/src/crypto/crypto_dh.cc @@ -69,7 +69,6 @@ void DiffieHellman::Initialize(Environment* env, Local target) { t->InstanceTemplate()->SetInternalFieldCount( DiffieHellman::kInternalFieldCount); - t->Inherit(BaseObject::GetConstructorTemplate(env)); SetProtoMethod(isolate, t, "generateKeys", GenerateKeys); SetProtoMethod(isolate, t, "computeSecret", ComputeSecret); diff --git a/src/crypto/crypto_ec.cc b/src/crypto/crypto_ec.cc index 3ccea99fb2bb..415464be04db 100644 --- a/src/crypto/crypto_ec.cc +++ b/src/crypto/crypto_ec.cc @@ -66,7 +66,6 @@ void ECDH::Initialize(Environment* env, Local target) { Local context = env->context(); Local t = NewFunctionTemplate(isolate, New); - t->Inherit(BaseObject::GetConstructorTemplate(env)); t->InstanceTemplate()->SetInternalFieldCount(ECDH::kInternalFieldCount); diff --git a/src/crypto/crypto_hash.cc b/src/crypto/crypto_hash.cc index 200603a85ef3..5627bac590f2 100644 --- a/src/crypto/crypto_hash.cc +++ b/src/crypto/crypto_hash.cc @@ -57,9 +57,7 @@ void Hash::Initialize(Environment* env, Local target) { Local context = env->context(); Local t = NewFunctionTemplate(isolate, New); - t->InstanceTemplate()->SetInternalFieldCount( - Hash::kInternalFieldCount); - t->Inherit(BaseObject::GetConstructorTemplate(env)); + t->InstanceTemplate()->SetInternalFieldCount(Hash::kInternalFieldCount); SetProtoMethod(isolate, t, "update", HashUpdate); SetProtoMethod(isolate, t, "digest", HashDigest); diff --git a/src/crypto/crypto_hmac.cc b/src/crypto/crypto_hmac.cc index ed78e21f118a..41c83b31eb21 100644 --- a/src/crypto/crypto_hmac.cc +++ b/src/crypto/crypto_hmac.cc @@ -41,9 +41,7 @@ void Hmac::Initialize(Environment* env, Local target) { Isolate* isolate = env->isolate(); Local t = NewFunctionTemplate(isolate, New); - t->InstanceTemplate()->SetInternalFieldCount( - Hmac::kInternalFieldCount); - t->Inherit(BaseObject::GetConstructorTemplate(env)); + t->InstanceTemplate()->SetInternalFieldCount(Hmac::kInternalFieldCount); SetProtoMethod(isolate, t, "init", HmacInit); SetProtoMethod(isolate, t, "update", HmacUpdate); diff --git a/src/crypto/crypto_keys.cc b/src/crypto/crypto_keys.cc index 0be2283d6017..1b8e9b25a699 100644 --- a/src/crypto/crypto_keys.cc +++ b/src/crypto/crypto_keys.cc @@ -901,7 +901,6 @@ v8::Local KeyObjectHandle::Initialize(Environment* env) { templ = NewFunctionTemplate(isolate, New); templ->InstanceTemplate()->SetInternalFieldCount( KeyObjectHandle::kInternalFieldCount); - templ->Inherit(BaseObject::GetConstructorTemplate(env)); SetProtoMethod(isolate, templ, "init", Init); SetProtoMethodNoSideEffect( @@ -1342,7 +1341,6 @@ void NativeKeyObject::CreateNativeKeyObjectClass( NewFunctionTemplate(isolate, NativeKeyObject::New); t->InstanceTemplate()->SetInternalFieldCount( KeyObjectHandle::kInternalFieldCount); - t->Inherit(BaseObject::GetConstructorTemplate(env)); Local ctor; if (!t->GetFunction(env->context()).ToLocal(&ctor)) diff --git a/src/crypto/crypto_sig.cc b/src/crypto/crypto_sig.cc index 92188911b35a..8e8b5f0c61e2 100644 --- a/src/crypto/crypto_sig.cc +++ b/src/crypto/crypto_sig.cc @@ -329,9 +329,7 @@ void Sign::Initialize(Environment* env, Local target) { Isolate* isolate = env->isolate(); Local t = NewFunctionTemplate(isolate, New); - t->InstanceTemplate()->SetInternalFieldCount( - SignBase::kInternalFieldCount); - t->Inherit(BaseObject::GetConstructorTemplate(env)); + t->InstanceTemplate()->SetInternalFieldCount(SignBase::kInternalFieldCount); SetProtoMethod(isolate, t, "init", SignInit); SetProtoMethod(isolate, t, "update", SignUpdate); @@ -459,9 +457,7 @@ void Verify::Initialize(Environment* env, Local target) { Isolate* isolate = env->isolate(); Local t = NewFunctionTemplate(isolate, New); - t->InstanceTemplate()->SetInternalFieldCount( - SignBase::kInternalFieldCount); - t->Inherit(BaseObject::GetConstructorTemplate(env)); + t->InstanceTemplate()->SetInternalFieldCount(SignBase::kInternalFieldCount); SetProtoMethod(isolate, t, "init", VerifyInit); SetProtoMethod(isolate, t, "update", VerifyUpdate); diff --git a/src/crypto/crypto_x509.cc b/src/crypto/crypto_x509.cc index e1b713644a1f..3541ea6c5f7c 100644 --- a/src/crypto/crypto_x509.cc +++ b/src/crypto/crypto_x509.cc @@ -59,7 +59,6 @@ Local X509Certificate::GetConstructorTemplate( tmpl = NewFunctionTemplate(isolate, nullptr); tmpl->InstanceTemplate()->SetInternalFieldCount( BaseObject::kInternalFieldCount); - tmpl->Inherit(BaseObject::GetConstructorTemplate(env)); tmpl->SetClassName( FIXED_ONE_BYTE_STRING(env->isolate(), "X509Certificate")); SetProtoMethod(isolate, tmpl, "subject", Subject); diff --git a/src/env.cc b/src/env.cc index 8ee2c10d089f..6fc1be04b836 100644 --- a/src/env.cc +++ b/src/env.cc @@ -480,7 +480,6 @@ void IsolateData::CreateProperties() { Local templ = FunctionTemplate::New(isolate()); templ->InstanceTemplate()->SetInternalFieldCount( BaseObject::kInternalFieldCount); - templ->Inherit(BaseObject::GetConstructorTemplate(this)); set_binding_data_ctor_template(templ); binding::CreateInternalBindingTemplates(this); diff --git a/src/env_properties.h b/src/env_properties.h index 05a4ac58380c..095094714aa4 100644 --- a/src/env_properties.h +++ b/src/env_properties.h @@ -330,7 +330,6 @@ #define PER_ISOLATE_TEMPLATE_PROPERTIES(V) \ V(async_wrap_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(blob_constructor_template, v8::FunctionTemplate) \ V(blob_reader_constructor_template, v8::FunctionTemplate) \ diff --git a/src/histogram.cc b/src/histogram.cc index 112a8911cfb4..5a2b1acf8976 100644 --- a/src/histogram.cc +++ b/src/histogram.cc @@ -288,7 +288,6 @@ Local HistogramBase::GetConstructorTemplate( tmpl = NewFunctionTemplate(isolate, New); Local classname = FIXED_ONE_BYTE_STRING(isolate, "Histogram"); tmpl->SetClassName(classname); - tmpl->Inherit(BaseObject::GetConstructorTemplate(isolate_data)); tmpl->InstanceTemplate()->SetInternalFieldCount( HistogramBase::kInternalFieldCount); diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 9b2b0b8334d1..77ee0dc9109e 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -768,7 +768,6 @@ void ModuleWrap::Initialize(Local target, Local tpl = NewFunctionTemplate(isolate, New); tpl->InstanceTemplate()->SetInternalFieldCount( ModuleWrap::kInternalFieldCount); - tpl->Inherit(BaseObject::GetConstructorTemplate(env)); SetProtoMethod(isolate, tpl, "link", Link); SetProtoMethod(isolate, tpl, "instantiate", Instantiate); diff --git a/src/node_binding.cc b/src/node_binding.cc index bd6ca33fcaf9..90855aada5da 100644 --- a/src/node_binding.cc +++ b/src/node_binding.cc @@ -565,7 +565,6 @@ void CreateInternalBindingTemplates(IsolateData* isolate_data) { FunctionTemplate::New(isolate_data->isolate()); \ templ->InstanceTemplate()->SetInternalFieldCount( \ BaseObject::kInternalFieldCount); \ - templ->Inherit(BaseObject::GetConstructorTemplate(isolate_data)); \ _register_isolate_##modname(isolate_data, templ); \ isolate_data->set_##modname##_binding(templ); \ } while (0); diff --git a/src/node_blob.cc b/src/node_blob.cc index b2fc527b3b50..40112f5d06af 100644 --- a/src/node_blob.cc +++ b/src/node_blob.cc @@ -131,7 +131,6 @@ Local Blob::GetConstructorTemplate(Environment* env) { tmpl = NewFunctionTemplate(isolate, nullptr); tmpl->InstanceTemplate()->SetInternalFieldCount( BaseObject::kInternalFieldCount); - tmpl->Inherit(BaseObject::GetConstructorTemplate(env)); tmpl->SetClassName( FIXED_ONE_BYTE_STRING(env->isolate(), "Blob")); SetProtoMethod(isolate, tmpl, "getReader", GetReader); @@ -281,7 +280,6 @@ Local Blob::Reader::GetConstructorTemplate(Environment* env) { tmpl = NewFunctionTemplate(isolate, nullptr); tmpl->InstanceTemplate()->SetInternalFieldCount( BaseObject::kInternalFieldCount); - tmpl->Inherit(BaseObject::GetConstructorTemplate(env)); tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "BlobReader")); SetProtoMethod(env->isolate(), tmpl, "pull", Pull); env->set_blob_reader_constructor_template(tmpl); diff --git a/src/node_i18n.cc b/src/node_i18n.cc index cdb264d6202e..e60b58b57185 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -875,7 +875,6 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data, // ConverterObject { Local t = NewFunctionTemplate(isolate, nullptr); - t->Inherit(BaseObject::GetConstructorTemplate(isolate_data)); t->InstanceTemplate()->SetInternalFieldCount( ConverterObject::kInternalFieldCount); Local converter_string = diff --git a/src/node_messaging.cc b/src/node_messaging.cc index ae9720a3359c..b40868a1ceef 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -301,7 +301,7 @@ class SerializerDelegate : public ValueSerializer::Delegate { } Maybe WriteHostObject(Isolate* isolate, Local object) override { - if (env_->base_object_ctor_template()->HasInstance(object)) { + if (BaseObject::IsBaseObject(object)) { return WriteHostObject( BaseObjectPtr { Unwrap(object) }); } @@ -490,7 +490,8 @@ Maybe Message::Serialize(Environment* env, array_buffers.push_back(ab); serializer.TransferArrayBuffer(id, ab); continue; - } else if (env->base_object_ctor_template()->HasInstance(entry)) { + } else if (entry->IsObject() && + BaseObject::IsBaseObject(entry.As())) { // Check if the source MessagePort is being transferred. if (!source_port.IsEmpty() && entry == source_port) { ThrowDataCloneException( @@ -1257,7 +1258,7 @@ JSTransferable::NestedTransferables() const { Local value; if (!list->Get(context, i).ToLocal(&value)) return Nothing(); - if (env()->base_object_ctor_template()->HasInstance(value)) + if (value->IsObject() && BaseObject::IsBaseObject(value.As())) ret.emplace_back(Unwrap(value)); } return Just(ret); @@ -1309,9 +1310,10 @@ BaseObjectPtr JSTransferable::Data::Deserialize( Local ret; CHECK(!env->messaging_deserialize_create_object().IsEmpty()); - if (!env->messaging_deserialize_create_object()->Call( - context, Null(env->isolate()), 1, &info).ToLocal(&ret) || - !env->base_object_ctor_template()->HasInstance(ret)) { + if (!env->messaging_deserialize_create_object() + ->Call(context, Null(env->isolate()), 1, &info) + .ToLocal(&ret) || + !ret->IsObject() || !BaseObject::IsBaseObject(ret.As())) { return {}; } @@ -1492,7 +1494,6 @@ static void InitMessaging(Local target, { Local t = NewFunctionTemplate(isolate, JSTransferable::New); - t->Inherit(BaseObject::GetConstructorTemplate(env)); t->InstanceTemplate()->SetInternalFieldCount( JSTransferable::kInternalFieldCount); SetConstructorFunction(context, target, "JSTransferable", t); diff --git a/src/node_serdes.cc b/src/node_serdes.cc index 6864f2d88b34..6698a1df81cb 100644 --- a/src/node_serdes.cc +++ b/src/node_serdes.cc @@ -462,7 +462,6 @@ void Initialize(Local target, ser->InstanceTemplate()->SetInternalFieldCount( SerializerContext::kInternalFieldCount); - ser->Inherit(BaseObject::GetConstructorTemplate(env)); SetProtoMethod(isolate, ser, "writeHeader", SerializerContext::WriteHeader); SetProtoMethod(isolate, ser, "writeValue", SerializerContext::WriteValue); @@ -490,7 +489,6 @@ void Initialize(Local target, des->InstanceTemplate()->SetInternalFieldCount( DeserializerContext::kInternalFieldCount); - des->Inherit(BaseObject::GetConstructorTemplate(env)); SetProtoMethod(isolate, des, "readHeader", DeserializerContext::ReadHeader); SetProtoMethod(isolate, des, "readValue", DeserializerContext::ReadValue); diff --git a/src/node_snapshotable.cc b/src/node_snapshotable.cc index fd8015782ca7..3fcc117b1c8f 100644 --- a/src/node_snapshotable.cc +++ b/src/node_snapshotable.cc @@ -1369,18 +1369,7 @@ StartupData SerializeNodeContextInternalFields(Local holder, // (most importantly, BaseObject::kSlot). // For Node.js this design is enough for all the native binding that are // serializable. - if (index != BaseObject::kEmbedderType) { - return StartupData{nullptr, 0}; - } - - void* type_ptr = holder->GetAlignedPointerFromInternalField(index); - if (type_ptr == nullptr) { - return StartupData{nullptr, 0}; - } - - uint16_t type = *(static_cast(type_ptr)); - per_process::Debug(DebugCategory::MKSNAPSHOT, "type = 0x%x\n", type); - if (type != kNodeEmbedderId) { + if (index != BaseObject::kEmbedderType || !BaseObject::IsBaseObject(holder)) { return StartupData{nullptr, 0}; } diff --git a/src/node_sockaddr.cc b/src/node_sockaddr.cc index 2fb768a284ce..b54962b29110 100644 --- a/src/node_sockaddr.cc +++ b/src/node_sockaddr.cc @@ -701,7 +701,6 @@ Local SocketAddressBlockListWrap::GetConstructorTemplate( Isolate* isolate = env->isolate(); tmpl = NewFunctionTemplate(isolate, SocketAddressBlockListWrap::New); tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "BlockList")); - tmpl->Inherit(BaseObject::GetConstructorTemplate(env)); tmpl->InstanceTemplate()->SetInternalFieldCount(kInternalFieldCount); SetProtoMethod(isolate, tmpl, "addAddress", AddAddress); SetProtoMethod(isolate, tmpl, "addRange", AddRange); @@ -757,7 +756,6 @@ Local SocketAddressBase::GetConstructorTemplate( tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "SocketAddress")); tmpl->InstanceTemplate()->SetInternalFieldCount( SocketAddressBase::kInternalFieldCount); - tmpl->Inherit(BaseObject::GetConstructorTemplate(env)); SetProtoMethod(isolate, tmpl, "detail", Detail); SetProtoMethod(isolate, tmpl, "legacyDetail", LegacyDetail); SetProtoMethodNoSideEffect(isolate, tmpl, "flowlabel", GetFlowLabel); diff --git a/src/node_trace_events.cc b/src/node_trace_events.cc index c84651dc832a..bd2eefafb68c 100644 --- a/src/node_trace_events.cc +++ b/src/node_trace_events.cc @@ -137,7 +137,6 @@ void NodeCategorySet::Initialize(Local target, NewFunctionTemplate(isolate, NodeCategorySet::New); category_set->InstanceTemplate()->SetInternalFieldCount( NodeCategorySet::kInternalFieldCount); - category_set->Inherit(BaseObject::GetConstructorTemplate(env)); SetProtoMethod(isolate, category_set, "enable", NodeCategorySet::Enable); SetProtoMethod(isolate, category_set, "disable", NodeCategorySet::Disable); diff --git a/src/node_util.cc b/src/node_util.cc index 0ce3af33c824..58f8363d4daa 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -468,7 +468,6 @@ void Initialize(Local target, NewFunctionTemplate(isolate, WeakReference::New); weak_ref->InstanceTemplate()->SetInternalFieldCount( WeakReference::kInternalFieldCount); - weak_ref->Inherit(BaseObject::GetConstructorTemplate(env)); SetProtoMethod(isolate, weak_ref, "get", WeakReference::Get); SetProtoMethod(isolate, weak_ref, "getRef", WeakReference::GetRef); SetProtoMethod(isolate, weak_ref, "incRef", WeakReference::IncRef); diff --git a/src/node_wasi.cc b/src/node_wasi.cc index 061de8e8b212..e1a16c4e4b7d 100644 --- a/src/node_wasi.cc +++ b/src/node_wasi.cc @@ -1271,7 +1271,6 @@ static void InitializePreview1(Local target, Local tmpl = NewFunctionTemplate(isolate, WASI::New); tmpl->InstanceTemplate()->SetInternalFieldCount(WASI::kInternalFieldCount); - tmpl->Inherit(BaseObject::GetConstructorTemplate(env)); #define V(F, name) \ SetFunction(WASI::F, env, name, tmpl); diff --git a/src/node_wasm_web_api.cc b/src/node_wasm_web_api.cc index 0f79f20fccb2..824ff66664a5 100644 --- a/src/node_wasm_web_api.cc +++ b/src/node_wasm_web_api.cc @@ -28,7 +28,6 @@ Local WasmStreamingObject::Initialize(Environment* env) { Isolate* isolate = env->isolate(); Local t = NewFunctionTemplate(isolate, New); - t->Inherit(BaseObject::GetConstructorTemplate(env)); t->InstanceTemplate()->SetInternalFieldCount( WasmStreamingObject::kInternalFieldCount); From 49a083cc26fd1819234e2f3f7a3684dcc8082bff Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 24 Mar 2023 22:18:27 +0100 Subject: [PATCH 2/2] fixup! src: use the internal field to determine if an object is a BaseObject --- src/base_object-inl.h | 4 ++-- src/base_object.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/base_object-inl.h b/src/base_object-inl.h index c8a455d5ecc7..feaeab306ace 100644 --- a/src/base_object-inl.h +++ b/src/base_object-inl.h @@ -79,14 +79,14 @@ bool BaseObject::IsBaseObject(v8::Local obj) { return ptr == &kNodeEmbedderId; } -void BaseObject::TagNodeObject(v8::Local object) { +void BaseObject::TagBaseObject(v8::Local object) { DCHECK_GE(object->InternalFieldCount(), BaseObject::kInternalFieldCount); object->SetAlignedPointerInInternalField(BaseObject::kEmbedderType, &kNodeEmbedderId); } void BaseObject::SetInternalFields(v8::Local object, void* slot) { - TagNodeObject(object); + TagBaseObject(object); object->SetAlignedPointerInInternalField(BaseObject::kSlot, slot); } diff --git a/src/base_object.h b/src/base_object.h index 37551473a847..96f661c41284 100644 --- a/src/base_object.h +++ b/src/base_object.h @@ -77,7 +77,7 @@ class BaseObject : public MemoryRetainer { static inline void SetInternalFields(v8::Local object, void* slot); static inline bool IsBaseObject(v8::Local object); - static inline void TagNodeObject(v8::Local object); + static inline void TagBaseObject(v8::Local object); static void LazilyInitializedJSTemplateConstructor( const v8::FunctionCallbackInfo& args); static inline BaseObject* FromJSObject(v8::Local object);