diff --git a/src/async_wrap-inl.h b/src/async_wrap-inl.h index afef24c7c64..432b22e6c8d 100644 --- a/src/async_wrap-inl.h +++ b/src/async_wrap-inl.h @@ -89,6 +89,15 @@ inline v8::Local AsyncWrap::GetConstructorTemplate( return GetConstructorTemplate(env->isolate_data()); } +// static +v8::Local AsyncWrap::MakeLazilyInitializedJSTemplate( + Environment* env, int internal_field_count) { + v8::Local t = + BaseObject::MakeLazilyInitializedJSTemplate(env, internal_field_count); + t->Inherit(AsyncWrap::GetConstructorTemplate(env)); + return t; +} + } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS diff --git a/src/async_wrap.h b/src/async_wrap.h index c00ce5ea2e8..94b2fe79fe1 100644 --- a/src/async_wrap.h +++ b/src/async_wrap.h @@ -115,6 +115,10 @@ class ExternalReferenceRegistry; class AsyncWrap : public BaseObject { public: + enum InternalFields { + kInternalFieldCount = BaseObject::kInternalFieldCount, + }; + enum ProviderType { #define V(PROVIDER) \ PROVIDER_ ## PROVIDER, @@ -228,6 +232,9 @@ class AsyncWrap : public BaseObject { bool IsDoneInitializing() const override; + static inline v8::Local MakeLazilyInitializedJSTemplate( + Environment* env, int internal_field_count = kInternalFieldCount); + private: ProviderType provider_type_ = PROVIDER_NONE; bool init_hook_ran_ = false; diff --git a/src/base_object.cc b/src/base_object.cc index 593fce4382a..ea27a62dd89 100644 --- a/src/base_object.cc +++ b/src/base_object.cc @@ -81,15 +81,16 @@ void BaseObject::LazilyInitializedJSTemplateConstructor( } Local BaseObject::MakeLazilyInitializedJSTemplate( - Environment* env) { - return MakeLazilyInitializedJSTemplate(env->isolate_data()); + Environment* env, int internal_field_count) { + return MakeLazilyInitializedJSTemplate(env->isolate_data(), + internal_field_count); } Local BaseObject::MakeLazilyInitializedJSTemplate( - IsolateData* isolate_data) { + IsolateData* isolate_data, int internal_field_count) { Local t = NewFunctionTemplate( isolate_data->isolate(), LazilyInitializedJSTemplateConstructor); - t->InstanceTemplate()->SetInternalFieldCount(BaseObject::kInternalFieldCount); + t->InstanceTemplate()->SetInternalFieldCount(internal_field_count); return t; } diff --git a/src/base_object.h b/src/base_object.h index b47e7da045c..c895cb4e993 100644 --- a/src/base_object.h +++ b/src/base_object.h @@ -106,9 +106,9 @@ class BaseObject : public MemoryRetainer { // the `BaseObject*` pointer) and a constructor that initializes that field // to `nullptr`. static v8::Local MakeLazilyInitializedJSTemplate( - IsolateData* isolate); + IsolateData* isolate, int internal_field_count = kInternalFieldCount); static v8::Local MakeLazilyInitializedJSTemplate( - Environment* env); + Environment* env, int internal_field_count = kInternalFieldCount); // Setter/Getter pair for internal fields that can be passed to SetAccessor. template diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index b15637f3e36..f5590972fdb 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -2219,19 +2219,13 @@ void Initialize(Local target, NODE_DEFINE_CONSTANT(target, DNS_ORDER_IPV4_FIRST); NODE_DEFINE_CONSTANT(target, DNS_ORDER_IPV6_FIRST); - Local aiw = - BaseObject::MakeLazilyInitializedJSTemplate(env); - aiw->Inherit(AsyncWrap::GetConstructorTemplate(env)); + Local aiw = AsyncWrap::MakeLazilyInitializedJSTemplate(env); SetConstructorFunction(context, target, "GetAddrInfoReqWrap", aiw); - Local niw = - BaseObject::MakeLazilyInitializedJSTemplate(env); - niw->Inherit(AsyncWrap::GetConstructorTemplate(env)); + Local niw = AsyncWrap::MakeLazilyInitializedJSTemplate(env); SetConstructorFunction(context, target, "GetNameInfoReqWrap", niw); - Local qrw = - BaseObject::MakeLazilyInitializedJSTemplate(env); - qrw->Inherit(AsyncWrap::GetConstructorTemplate(env)); + Local qrw = AsyncWrap::MakeLazilyInitializedJSTemplate(env); SetConstructorFunction(context, target, "QueryReqWrap", qrw); Local channel_wrap = diff --git a/src/crypto/crypto_keys.cc b/src/crypto/crypto_keys.cc index fe852bdebac..650abb51664 100644 --- a/src/crypto/crypto_keys.cc +++ b/src/crypto/crypto_keys.cc @@ -1081,7 +1081,7 @@ void NativeKeyObject::CreateNativeKeyObjectClass( Local t = NewFunctionTemplate(isolate, NativeKeyObject::New); t->InstanceTemplate()->SetInternalFieldCount( - KeyObjectHandle::kInternalFieldCount); + NativeKeyObject::kInternalFieldCount); Local ctor; if (!t->GetFunction(env->context()).ToLocal(&ctor)) diff --git a/src/crypto/crypto_sig.cc b/src/crypto/crypto_sig.cc index 2f6e683e349..19248cf555d 100644 --- a/src/crypto/crypto_sig.cc +++ b/src/crypto/crypto_sig.cc @@ -323,7 +323,7 @@ void Sign::Initialize(Environment* env, Local target) { Isolate* isolate = env->isolate(); Local t = NewFunctionTemplate(isolate, New); - t->InstanceTemplate()->SetInternalFieldCount(SignBase::kInternalFieldCount); + t->InstanceTemplate()->SetInternalFieldCount(Sign::kInternalFieldCount); SetProtoMethod(isolate, t, "init", SignInit); SetProtoMethod(isolate, t, "update", SignUpdate); @@ -458,7 +458,7 @@ void Verify::Initialize(Environment* env, Local target) { Isolate* isolate = env->isolate(); Local t = NewFunctionTemplate(isolate, New); - t->InstanceTemplate()->SetInternalFieldCount(SignBase::kInternalFieldCount); + t->InstanceTemplate()->SetInternalFieldCount(Verify::kInternalFieldCount); SetProtoMethod(isolate, t, "init", VerifyInit); SetProtoMethod(isolate, t, "update", VerifyUpdate); diff --git a/src/crypto/crypto_tls.cc b/src/crypto/crypto_tls.cc index a80685790bd..bdcdaf1a411 100644 --- a/src/crypto/crypto_tls.cc +++ b/src/crypto/crypto_tls.cc @@ -2186,11 +2186,11 @@ void TLSWrap::Initialize( NODE_DEFINE_CONSTANT(target, HAVE_SSL_TRACE); - Local t = BaseObject::MakeLazilyInitializedJSTemplate(env); + Local t = AsyncWrap::MakeLazilyInitializedJSTemplate(env); Local tlsWrapString = FIXED_ONE_BYTE_STRING(env->isolate(), "TLSWrap"); t->SetClassName(tlsWrapString); - t->InstanceTemplate()->SetInternalFieldCount(StreamBase::kInternalFieldCount); + t->InstanceTemplate()->SetInternalFieldCount(TLSWrap::kInternalFieldCount); Local get_write_queue_size = FunctionTemplate::New(env->isolate(), diff --git a/src/crypto/crypto_tls.h b/src/crypto/crypto_tls.h index ed1ee337b42..1e6d3b7edbc 100644 --- a/src/crypto/crypto_tls.h +++ b/src/crypto/crypto_tls.h @@ -43,6 +43,11 @@ class TLSWrap : public AsyncWrap, public StreamBase, public StreamListener { public: + enum InternalFields { + kInternalFieldCount = std::max(AsyncWrap::kInternalFieldCount, + StreamBase::kInternalFieldCount), + }; + enum class Kind { kClient, kServer diff --git a/src/crypto/crypto_util.h b/src/crypto/crypto_util.h index 1592134716d..8bcfc05a928 100644 --- a/src/crypto/crypto_util.h +++ b/src/crypto/crypto_util.h @@ -405,7 +405,7 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork { v8::Local job = NewFunctionTemplate(isolate, new_fn); job->Inherit(AsyncWrap::GetConstructorTemplate(env)); job->InstanceTemplate()->SetInternalFieldCount( - AsyncWrap::kInternalFieldCount); + CryptoJob::kInternalFieldCount); SetProtoMethod(isolate, job, "run", Run); SetConstructorFunction(context, target, CryptoJobTraits::JobName, job); } diff --git a/src/crypto/crypto_x509.cc b/src/crypto/crypto_x509.cc index f616223cfb0..f21029985ee 100644 --- a/src/crypto/crypto_x509.cc +++ b/src/crypto/crypto_x509.cc @@ -843,7 +843,7 @@ Local X509Certificate::GetConstructorTemplate( Isolate* isolate = env->isolate(); tmpl = NewFunctionTemplate(isolate, nullptr); tmpl->InstanceTemplate()->SetInternalFieldCount( - BaseObject::kInternalFieldCount); + X509Certificate::kInternalFieldCount); tmpl->SetClassName( FIXED_ONE_BYTE_STRING(env->isolate(), "X509Certificate")); SetProtoMethodNoSideEffect(isolate, tmpl, "subject", Subject); diff --git a/src/heap_utils.cc b/src/heap_utils.cc index fa12d88143b..b80bf79be6e 100644 --- a/src/heap_utils.cc +++ b/src/heap_utils.cc @@ -269,6 +269,11 @@ class HeapSnapshotStream : public AsyncWrap, public StreamBase, public v8::OutputStream { public: + enum InternalFields { + kInternalFieldCount = std::max(AsyncWrap::kInternalFieldCount, + StreamBase::kInternalFieldCount), + }; + HeapSnapshotStream( Environment* env, HeapSnapshotPointer&& snapshot, @@ -403,7 +408,7 @@ BaseObjectPtr CreateHeapSnapshotStream( Local os = FunctionTemplate::New(env->isolate()); os->Inherit(AsyncWrap::GetConstructorTemplate(env)); Local ost = os->InstanceTemplate(); - ost->SetInternalFieldCount(StreamBase::kInternalFieldCount); + ost->SetInternalFieldCount(HeapSnapshotStream::kInternalFieldCount); os->SetClassName( FIXED_ONE_BYTE_STRING(env->isolate(), "HeapSnapshotStream")); StreamBase::AddMethods(env, os); diff --git a/src/histogram.cc b/src/histogram.cc index 836a51b0e5a..2bcfcbdd954 100644 --- a/src/histogram.cc +++ b/src/histogram.cc @@ -270,7 +270,7 @@ Local HistogramBase::GetConstructorTemplate( Local classname = FIXED_ONE_BYTE_STRING(isolate, "Histogram"); tmpl->SetClassName(classname); auto instance = tmpl->InstanceTemplate(); - instance->SetInternalFieldCount(HistogramImpl::kInternalFieldCount); + instance->SetInternalFieldCount(HistogramBase::kInternalFieldCount); SetFastMethod(isolate, instance, "record", Record, &fast_record_); SetFastMethod( isolate, instance, "recordDelta", RecordDelta, &fast_record_delta_); @@ -326,7 +326,7 @@ Local IntervalHistogram::GetConstructorTemplate( tmpl->Inherit(HandleWrap::GetConstructorTemplate(env)); tmpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "Histogram")); auto instance = tmpl->InstanceTemplate(); - instance->SetInternalFieldCount(HistogramImpl::kInternalFieldCount); + instance->SetInternalFieldCount(IntervalHistogram::kInternalFieldCount); HistogramImpl::AddMethods(isolate, tmpl); SetFastMethod(isolate, instance, "start", Start, &fast_start_); SetFastMethod(isolate, instance, "stop", Stop, &fast_stop_); diff --git a/src/histogram.h b/src/histogram.h index 29303bd1664..31c6564b9b1 100644 --- a/src/histogram.h +++ b/src/histogram.h @@ -71,7 +71,7 @@ class HistogramImpl { public: enum InternalFields { kSlot = BaseObject::kSlot, - kImplField = BaseObject::kInternalFieldCount, + kImplField = HandleWrap::kInternalFieldCount, kInternalFieldCount }; @@ -133,6 +133,11 @@ class HistogramImpl { class HistogramBase final : public BaseObject, public HistogramImpl { public: + enum InternalFields { + kInternalFieldCount = std::max( + BaseObject::kInternalFieldCount, HistogramImpl::kInternalFieldCount), + }; + static v8::Local GetConstructorTemplate( IsolateData* isolate_data); static void Initialize(IsolateData* isolate_data, @@ -203,6 +208,11 @@ class HistogramBase final : public BaseObject, public HistogramImpl { class IntervalHistogram final : public HandleWrap, public HistogramImpl { public: + enum InternalFields { + kInternalFieldCount = std::max( + HandleWrap::kInternalFieldCount, HistogramImpl::kInternalFieldCount), + }; + enum class StartFlags { NONE, RESET diff --git a/src/js_stream.cc b/src/js_stream.cc index cf04e5ef757..0d6d6a7ac80 100644 --- a/src/js_stream.cc +++ b/src/js_stream.cc @@ -210,8 +210,7 @@ void JSStream::Initialize(Local target, Isolate* isolate = env->isolate(); Local t = NewFunctionTemplate(isolate, New); - t->InstanceTemplate() - ->SetInternalFieldCount(StreamBase::kInternalFieldCount); + t->InstanceTemplate()->SetInternalFieldCount(JSStream::kInternalFieldCount); t->Inherit(AsyncWrap::GetConstructorTemplate(env)); SetProtoMethod(isolate, t, "finishWrite", Finish); diff --git a/src/js_stream.h b/src/js_stream.h index d96b3d0062d..b8c88fd812d 100644 --- a/src/js_stream.h +++ b/src/js_stream.h @@ -12,6 +12,11 @@ class Environment; class JSStream : public AsyncWrap, public StreamBase { public: + enum InternalFields { + kInternalFieldCount = std::max(AsyncWrap::kInternalFieldCount, + StreamBase::kInternalFieldCount), + }; + static void Initialize(v8::Local target, v8::Local unused, v8::Local context, diff --git a/src/node_blob.cc b/src/node_blob.cc index bb019dc62c1..a740bc5e13b 100644 --- a/src/node_blob.cc +++ b/src/node_blob.cc @@ -146,8 +146,7 @@ Local Blob::GetConstructorTemplate(Environment* env) { if (tmpl.IsEmpty()) { Isolate* isolate = env->isolate(); tmpl = NewFunctionTemplate(isolate, nullptr); - tmpl->InstanceTemplate()->SetInternalFieldCount( - BaseObject::kInternalFieldCount); + tmpl->InstanceTemplate()->SetInternalFieldCount(Blob::kInternalFieldCount); tmpl->SetClassName( FIXED_ONE_BYTE_STRING(env->isolate(), "Blob")); SetProtoMethod(isolate, tmpl, "getReader", GetReader); @@ -309,7 +308,7 @@ Local Blob::Reader::GetConstructorTemplate(Environment* env) { Isolate* isolate = env->isolate(); tmpl = NewFunctionTemplate(isolate, nullptr); tmpl->InstanceTemplate()->SetInternalFieldCount( - BaseObject::kInternalFieldCount); + Blob::Reader::kInternalFieldCount); 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_file.h b/src/node_file.h index bdad1ae25f4..a9e1b0152a9 100644 --- a/src/node_file.h +++ b/src/node_file.h @@ -321,7 +321,8 @@ class FileHandleReadWrap final : public ReqWrap { class FileHandle final : public AsyncWrap, public StreamBase { public: enum InternalFields { - kFileHandleBaseField = StreamBase::kInternalFieldCount, + kFileHandleBaseField = std::max(AsyncWrap::kInternalFieldCount, + StreamBase::kInternalFieldCount), kClosingPromiseSlot, kInternalFieldCount }; diff --git a/src/node_http2.cc b/src/node_http2.cc index 403d9982ebd..84a81f6817a 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -3508,7 +3508,7 @@ void Initialize(Local target, Local setting = FunctionTemplate::New(env->isolate()); setting->Inherit(AsyncWrap::GetConstructorTemplate(env)); Local settingt = setting->InstanceTemplate(); - settingt->SetInternalFieldCount(AsyncWrap::kInternalFieldCount); + settingt->SetInternalFieldCount(Http2Settings::kInternalFieldCount); env->set_http2settings_constructor_template(settingt); Local stream = FunctionTemplate::New(env->isolate()); @@ -3524,7 +3524,7 @@ void Initialize(Local target, stream->Inherit(AsyncWrap::GetConstructorTemplate(env)); StreamBase::AddMethods(env, stream); Local streamt = stream->InstanceTemplate(); - streamt->SetInternalFieldCount(StreamBase::kInternalFieldCount); + streamt->SetInternalFieldCount(Http2Stream::kInternalFieldCount); env->set_http2stream_constructor_template(streamt); SetConstructorFunction(context, target, "Http2Stream", stream); diff --git a/src/node_http2.h b/src/node_http2.h index 91046052927..04ccbca55b0 100644 --- a/src/node_http2.h +++ b/src/node_http2.h @@ -270,6 +270,11 @@ using Http2Header = NgHeader; class Http2Stream : public AsyncWrap, public StreamBase { public: + enum InternalFields { + kInternalFieldCount = std::max(AsyncWrap::kInternalFieldCount, + StreamBase::kInternalFieldCount), + }; + static Http2Stream* New( Http2Session* session, int32_t id, diff --git a/src/node_postmortem_metadata.cc b/src/node_postmortem_metadata.cc index ea7396e54c8..e40d82c0a5d 100644 --- a/src/node_postmortem_metadata.cc +++ b/src/node_postmortem_metadata.cc @@ -38,6 +38,8 @@ extern "C" { int nodedbg_const_ContextEmbedderIndex__kEnvironment__int; int nodedbg_const_BaseObject__kInternalFieldCount__int; +int nodedbg_const_HandleWrap__kInternalFieldCount__int; +int nodedbg_const_ReqWrap__kInternalFieldCount__int; uintptr_t nodedbg_offset_ExternalString__data__uintptr_t; uintptr_t nodedbg_offset_ReqWrap__req_wrap_queue___ListNode_ReqWrapQueue; @@ -54,6 +56,10 @@ int GenDebugSymbols() { ContextEmbedderIndex::kEnvironment; nodedbg_const_BaseObject__kInternalFieldCount__int = BaseObject::kInternalFieldCount; + nodedbg_const_HandleWrap__kInternalFieldCount__int = + HandleWrap::kInternalFieldCount; + nodedbg_const_ReqWrap__kInternalFieldCount__int = + ReqWrap::kInternalFieldCount; nodedbg_offset_ExternalString__data__uintptr_t = NODE_OFF_EXTSTR_DATA; nodedbg_offset_ReqWrap__req_wrap_queue___ListNode_ReqWrapQueue = diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index e959795bf5f..4a9418b1e2c 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -2503,7 +2503,7 @@ Local StatementSyncIterator::GetConstructorTemplate( tmpl = NewFunctionTemplate(isolate, IllegalConstructor); tmpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "StatementSyncIterator")); tmpl->InstanceTemplate()->SetInternalFieldCount( - StatementSync::kInternalFieldCount); + StatementSyncIterator::kInternalFieldCount); SetProtoMethod(isolate, tmpl, "next", StatementSyncIterator::Next); SetProtoMethod(isolate, tmpl, "return", StatementSyncIterator::Return); env->set_sqlite_statement_sync_iterator_constructor_template(tmpl); diff --git a/src/node_v8.cc b/src/node_v8.cc index 3ec20892e07..184fbc4d80a 100644 --- a/src/node_v8.cc +++ b/src/node_v8.cc @@ -684,7 +684,7 @@ void Initialize(Local target, // GCProfiler Local t = NewFunctionTemplate(env->isolate(), GCProfiler::New); - t->InstanceTemplate()->SetInternalFieldCount(BaseObject::kInternalFieldCount); + t->InstanceTemplate()->SetInternalFieldCount(GCProfiler::kInternalFieldCount); SetProtoMethod(env->isolate(), t, "start", GCProfiler::Start); SetProtoMethod(env->isolate(), t, "stop", GCProfiler::Stop); SetConstructorFunction(context, target, "GCProfiler", t); diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index bdb59a35e96..8ce9088cd09 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -72,7 +72,7 @@ void PipeWrap::Initialize(Local target, Isolate* isolate = env->isolate(); Local t = NewFunctionTemplate(isolate, New); - t->InstanceTemplate()->SetInternalFieldCount(StreamBase::kInternalFieldCount); + t->InstanceTemplate()->SetInternalFieldCount(PipeWrap::kInternalFieldCount); t->Inherit(LibuvStreamWrap::GetConstructorTemplate(env)); @@ -91,8 +91,7 @@ void PipeWrap::Initialize(Local target, env->set_pipe_constructor_template(t); // Create FunctionTemplate for PipeConnectWrap. - auto cwt = BaseObject::MakeLazilyInitializedJSTemplate(env); - cwt->Inherit(AsyncWrap::GetConstructorTemplate(env)); + auto cwt = AsyncWrap::MakeLazilyInitializedJSTemplate(env); SetConstructorFunction(context, target, "PipeConnectWrap", cwt); // Define constants diff --git a/src/quic/logstream.h b/src/quic/logstream.h index b5f2b59e3aa..b5f4f9af387 100644 --- a/src/quic/logstream.h +++ b/src/quic/logstream.h @@ -17,6 +17,10 @@ class LogStream : public AsyncWrap, public StreamBase { public: static v8::Local GetConstructorTemplate( Environment* env); + enum InternalFields { + kInternalFieldCount = std::max(AsyncWrap::kInternalFieldCount, + StreamBase::kInternalFieldCount), + }; static BaseObjectPtr Create(Environment* env); diff --git a/src/stream_base.h b/src/stream_base.h index ccbd769ceaf..be00134eb1f 100644 --- a/src/stream_base.h +++ b/src/stream_base.h @@ -37,7 +37,7 @@ class StreamReq { // BaseObject, and the slots are used for the identical purpose. enum InternalFields { kSlot = BaseObject::kSlot, - kStreamReqField = BaseObject::kInternalFieldCount, + kStreamReqField = AsyncWrap::kInternalFieldCount, kInternalFieldCount }; @@ -310,7 +310,7 @@ class StreamBase : public StreamResource { // BaseObject (it's possible for it not to, however). enum InternalFields { kSlot = BaseObject::kSlot, - kStreamBaseField = BaseObject::kInternalFieldCount, + kStreamBaseField = AsyncWrap::kInternalFieldCount, kOnReadFunctionField, kInternalFieldCount }; @@ -440,6 +440,11 @@ class StreamBase : public StreamResource { template class SimpleShutdownWrap : public ShutdownWrap, public OtherBase { public: + enum InternalFields { + kInternalFieldCount = std::max(ShutdownWrap::kInternalFieldCount, + OtherBase::kInternalFieldCount), + }; + SimpleShutdownWrap(StreamBase* stream, v8::Local req_wrap_obj); @@ -457,6 +462,11 @@ class SimpleShutdownWrap : public ShutdownWrap, public OtherBase { template class SimpleWriteWrap : public WriteWrap, public OtherBase { public: + enum InternalFields { + kInternalFieldCount = std::max(WriteWrap::kInternalFieldCount, + OtherBase::kInternalFieldCount), + }; + SimpleWriteWrap(StreamBase* stream, v8::Local req_wrap_obj); diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index f45bda17ef2..f90924c71e8 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -72,7 +72,8 @@ void LibuvStreamWrap::Initialize(Local target, Local sw = NewFunctionTemplate(isolate, IsConstructCallCallback); - sw->InstanceTemplate()->SetInternalFieldCount(StreamReq::kInternalFieldCount); + sw->InstanceTemplate()->SetInternalFieldCount( + ShutdownWrap::kInternalFieldCount); // we need to set handle and callback to null, // so that those fields are created and functions @@ -93,8 +94,7 @@ void LibuvStreamWrap::Initialize(Local target, Local ww = FunctionTemplate::New(isolate, IsConstructCallCallback); - ww->InstanceTemplate()->SetInternalFieldCount( - StreamReq::kInternalFieldCount); + ww->InstanceTemplate()->SetInternalFieldCount(WriteWrap::kInternalFieldCount); ww->Inherit(AsyncWrap::GetConstructorTemplate(env)); SetConstructorFunction(context, target, "WriteWrap", ww); env->set_write_wrap_template(ww->InstanceTemplate()); @@ -141,7 +141,7 @@ Local LibuvStreamWrap::GetConstructorTemplate( tmpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "LibuvStreamWrap")); tmpl->Inherit(HandleWrap::GetConstructorTemplate(env)); tmpl->InstanceTemplate()->SetInternalFieldCount( - StreamBase::kInternalFieldCount); + LibuvStreamWrap::kInternalFieldCount); Local get_write_queue_size = FunctionTemplate::New(isolate, GetWriteQueueSize, diff --git a/src/stream_wrap.h b/src/stream_wrap.h index 85a675d04f2..93db2a9e686 100644 --- a/src/stream_wrap.h +++ b/src/stream_wrap.h @@ -35,6 +35,11 @@ class ExternalReferenceRegistry; class LibuvStreamWrap : public HandleWrap, public StreamBase { public: + enum InternalFields { + kInternalFieldCount = std::max(HandleWrap::kInternalFieldCount, + StreamBase::kInternalFieldCount), + }; + static void Initialize(v8::Local target, v8::Local unused, v8::Local context, diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 72e2843636c..dba2eb2fd41 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -79,7 +79,7 @@ void TCPWrap::Initialize(Local target, Isolate* isolate = env->isolate(); Local t = NewFunctionTemplate(isolate, New); - t->InstanceTemplate()->SetInternalFieldCount(StreamBase::kInternalFieldCount); + t->InstanceTemplate()->SetInternalFieldCount(TCPWrap::kInternalFieldCount); // Init properties t->InstanceTemplate()->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "reading"), @@ -115,9 +115,7 @@ void TCPWrap::Initialize(Local target, env->set_tcp_constructor_template(t); // Create FunctionTemplate for TCPConnectWrap. - Local cwt = - BaseObject::MakeLazilyInitializedJSTemplate(env); - cwt->Inherit(AsyncWrap::GetConstructorTemplate(env)); + Local cwt = AsyncWrap::MakeLazilyInitializedJSTemplate(env); SetConstructorFunction(context, target, "TCPConnectWrap", cwt); // Define constants diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index 37c58cf0cb7..3086e859a54 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -60,7 +60,7 @@ void TTYWrap::Initialize(Local target, Local t = NewFunctionTemplate(isolate, New); t->SetClassName(ttyString); - t->InstanceTemplate()->SetInternalFieldCount(StreamBase::kInternalFieldCount); + t->InstanceTemplate()->SetInternalFieldCount(TTYWrap::kInternalFieldCount); t->Inherit(LibuvStreamWrap::GetConstructorTemplate(env)); SetProtoMethodNoSideEffect( diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index d2e9d1e1a76..429db333bed 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -223,9 +223,7 @@ void UDPWrap::Initialize(Local target, env->set_udp_constructor_function(t->GetFunction(context).ToLocalChecked()); // Create FunctionTemplate for SendWrap - Local swt = - BaseObject::MakeLazilyInitializedJSTemplate(env); - swt->Inherit(AsyncWrap::GetConstructorTemplate(env)); + Local swt = AsyncWrap::MakeLazilyInitializedJSTemplate(env); SetConstructorFunction(context, target, "SendWrap", swt); Local constants = Object::New(isolate); diff --git a/test/cctest/test_node_postmortem_metadata.cc b/test/cctest/test_node_postmortem_metadata.cc index a6f7b9f3d0e..fc147195bb1 100644 --- a/test/cctest/test_node_postmortem_metadata.cc +++ b/test/cctest/test_node_postmortem_metadata.cc @@ -16,6 +16,8 @@ extern uintptr_t extern int debug_symbols_generated; extern int nodedbg_const_ContextEmbedderIndex__kEnvironment__int; extern int nodedbg_const_BaseObject__kInternalFieldCount__int; +extern int nodedbg_const_HandleWrap__kInternalFieldCount__int; +extern int nodedbg_const_ReqWrap__kInternalFieldCount__int; extern uintptr_t nodedbg_offset_Environment_HandleWrapQueue__head___ListNode_HandleWrap; extern uintptr_t @@ -76,6 +78,18 @@ TEST_F(DebugSymbolsTest, BaseObjectkInternalFieldCount) { kInternalFieldCount); } +TEST_F(DebugSymbolsTest, HandleWrapInternalFieldCount) { + int kInternalFieldCount = node::HandleWrap::kInternalFieldCount; + EXPECT_EQ(nodedbg_const_HandleWrap__kInternalFieldCount__int, + kInternalFieldCount); +} + +TEST_F(DebugSymbolsTest, ReqWrapInternalFieldCount) { + int kInternalFieldCount = node::ReqWrap::kInternalFieldCount; + EXPECT_EQ(nodedbg_const_ReqWrap__kInternalFieldCount__int, + kInternalFieldCount); +} + TEST_F(DebugSymbolsTest, ExternalStringDataOffset) { EXPECT_EQ(nodedbg_offset_ExternalString__data__uintptr_t, NODE_OFF_EXTSTR_DATA); @@ -149,7 +163,7 @@ TEST_F(DebugSymbolsTest, HandleWrapList) { auto obj_template = v8::FunctionTemplate::New(isolate_); obj_template->InstanceTemplate()->SetInternalFieldCount( - nodedbg_const_BaseObject__kInternalFieldCount__int); + nodedbg_const_HandleWrap__kInternalFieldCount__int); v8::Local object = obj_template->GetFunction(env.context()) .ToLocalChecked() @@ -182,7 +196,7 @@ TEST_F(DebugSymbolsTest, ReqWrapList) { auto obj_template = v8::FunctionTemplate::New(isolate_); obj_template->InstanceTemplate()->SetInternalFieldCount( - nodedbg_const_BaseObject__kInternalFieldCount__int); + nodedbg_const_ReqWrap__kInternalFieldCount__int); v8::Local object = obj_template->GetFunction(env.context()) .ToLocalChecked()