diff --git a/src/base_object-inl.h b/src/base_object-inl.h index ad900b6399f149..bb1e8d4b46bce3 100644 --- a/src/base_object-inl.h +++ b/src/base_object-inl.h @@ -148,15 +148,17 @@ bool BaseObject::IsWeakOrDetached() const { return pd->wants_weak_jsobj || pd->is_detached; } +void BaseObject::LazilyInitializedJSTemplateConstructor( + const v8::FunctionCallbackInfo& args) { + DCHECK(args.IsConstructCall()); + DCHECK_GT(args.This()->InternalFieldCount(), 0); + args.This()->SetAlignedPointerInInternalField(BaseObject::kSlot, nullptr); +} + v8::Local BaseObject::MakeLazilyInitializedJSTemplate(Environment* env) { - auto constructor = [](const v8::FunctionCallbackInfo& args) { - DCHECK(args.IsConstructCall()); - DCHECK_GT(args.This()->InternalFieldCount(), 0); - args.This()->SetAlignedPointerInInternalField(BaseObject::kSlot, nullptr); - }; - - v8::Local t = env->NewFunctionTemplate(constructor); + v8::Local t = + env->NewFunctionTemplate(LazilyInitializedJSTemplateConstructor); t->Inherit(BaseObject::GetConstructorTemplate(env)); t->InstanceTemplate()->SetInternalFieldCount( BaseObject::kInternalFieldCount); diff --git a/src/base_object.h b/src/base_object.h index ec9d4a69d537b2..d46a0f216009c6 100644 --- a/src/base_object.h +++ b/src/base_object.h @@ -65,6 +65,8 @@ class BaseObject : public MemoryRetainer { // was also passed to the `BaseObject()` constructor initially. // This may return `nullptr` if the C++ object has not been constructed yet, // e.g. when the JS object used `MakeLazilyInitializedJSTemplate`. + static inline void LazilyInitializedJSTemplateConstructor( + const v8::FunctionCallbackInfo& args); static inline BaseObject* FromJSObject(v8::Local object); template static inline T* FromJSObject(v8::Local object); diff --git a/src/node_dtrace.cc b/src/node_dtrace.cc index 3c407f3447f171..7808a649a4a088 100644 --- a/src/node_dtrace.cc +++ b/src/node_dtrace.cc @@ -44,6 +44,7 @@ #include "env-inl.h" #include "node_errors.h" +#include "node_external_reference.h" #include @@ -288,6 +289,14 @@ void InitDTrace(Environment* env) { }, env); } +#define NODE_PROBES(V) \ + V(DTRACE_NET_SERVER_CONNECTION) \ + V(DTRACE_NET_STREAM_END) \ + V(DTRACE_HTTP_SERVER_REQUEST) \ + V(DTRACE_HTTP_SERVER_RESPONSE) \ + V(DTRACE_HTTP_CLIENT_REQUEST) \ + V(DTRACE_HTTP_CLIENT_RESPONSE) + void InitializeDTrace(Local target, Local unused, Local context, @@ -295,16 +304,20 @@ void InitializeDTrace(Local target, Environment* env = Environment::GetCurrent(context); #if defined HAVE_DTRACE || defined HAVE_ETW -# define NODE_PROBE(name) env->SetMethod(target, #name, name); - NODE_PROBE(DTRACE_NET_SERVER_CONNECTION) - NODE_PROBE(DTRACE_NET_STREAM_END) - NODE_PROBE(DTRACE_HTTP_SERVER_REQUEST) - NODE_PROBE(DTRACE_HTTP_SERVER_RESPONSE) - NODE_PROBE(DTRACE_HTTP_CLIENT_REQUEST) - NODE_PROBE(DTRACE_HTTP_CLIENT_RESPONSE) -# undef NODE_PROBE -#endif +#define V(name) env->SetMethod(target, #name, name); + NODE_PROBES(V) +#undef V +#endif // defined HAVE_DTRACE || defined HAVE_ETW +} + +void RegisterDtraceExternalReferences(ExternalReferenceRegistry* registry) { +#if defined HAVE_DTRACE || defined HAVE_ETW +#define V(name) registry->Register(name); + NODE_PROBES(V) +#undef V +#endif // defined HAVE_DTRACE || defined HAVE_ETW } } // namespace node NODE_MODULE_CONTEXT_AWARE_INTERNAL(dtrace, node::InitializeDTrace) +NODE_MODULE_EXTERNAL_REFERENCE(dtrace, node::RegisterDtraceExternalReferences) diff --git a/src/node_external_reference.cc b/src/node_external_reference.cc index 73e1489865d3a4..94198719b6a002 100644 --- a/src/node_external_reference.cc +++ b/src/node_external_reference.cc @@ -1,6 +1,7 @@ #include "node_external_reference.h" #include #include +#include "base_object-inl.h" #include "util.h" namespace node { @@ -13,6 +14,8 @@ const std::vector& ExternalReferenceRegistry::external_references() { } ExternalReferenceRegistry::ExternalReferenceRegistry() { + this->Register(BaseObject::LazilyInitializedJSTemplateConstructor); + #define V(modname) _register_external_reference_##modname(this); EXTERNAL_REFERENCE_BINDING_LIST(V) #undef V diff --git a/src/node_external_reference.h b/src/node_external_reference.h index 8d2de64ad43445..4ebaa8d27feae8 100644 --- a/src/node_external_reference.h +++ b/src/node_external_reference.h @@ -65,12 +65,17 @@ class ExternalReferenceRegistry { V(performance) \ V(process_methods) \ V(process_object) \ + V(report) \ V(task_queue) \ + V(tcp_wrap) \ + V(tty_wrap) \ V(url) \ V(util) \ + V(pipe_wrap) \ V(serdes) \ V(string_decoder) \ V(stream_wrap) \ + V(signal_wrap) \ V(trace_events) \ V(timers) \ V(types) \ @@ -92,10 +97,17 @@ class ExternalReferenceRegistry { #define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V) #endif // HAVE_INSPECTOR +#if HAVE_DTRACE || HAVE_ETW +#define EXTERNAL_REFERENCE_BINDING_LIST_DTRACE(V) V(dtrace) +#else +#define EXTERNAL_REFERENCE_BINDING_LIST_DTRACE(V) +#endif + #define EXTERNAL_REFERENCE_BINDING_LIST(V) \ EXTERNAL_REFERENCE_BINDING_LIST_BASE(V) \ EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V) \ - EXTERNAL_REFERENCE_BINDING_LIST_I18N(V) + EXTERNAL_REFERENCE_BINDING_LIST_I18N(V) \ + EXTERNAL_REFERENCE_BINDING_LIST_DTRACE(V) } // namespace node diff --git a/src/node_process_object.cc b/src/node_process_object.cc index 587b4ecb936835..29f6569a45e5b2 100644 --- a/src/node_process_object.cc +++ b/src/node_process_object.cc @@ -211,6 +211,11 @@ void PatchProcessObject(const FunctionCallbackInfo& args) { void RegisterProcessExternalReferences(ExternalReferenceRegistry* registry) { registry->Register(RawDebug); + registry->Register(GetParentProcessId); + registry->Register(DebugPortSetter); + registry->Register(DebugPortGetter); + registry->Register(ProcessTitleSetter); + registry->Register(ProcessTitleGetter); } } // namespace node diff --git a/src/node_report_module.cc b/src/node_report_module.cc index 190755a85b2369..160498c6276a3f 100644 --- a/src/node_report_module.cc +++ b/src/node_report_module.cc @@ -1,5 +1,6 @@ #include "env.h" #include "node_errors.h" +#include "node_external_reference.h" #include "node_internals.h" #include "node_options.h" #include "node_report.h" @@ -196,6 +197,26 @@ static void Initialize(Local exports, SetReportOnUncaughtException); } +void RegisterExternalReferences(node::ExternalReferenceRegistry* registry) { + registry->Register(WriteReport); + registry->Register(GetReport); + registry->Register(GetCompact); + registry->Register(SetCompact); + registry->Register(GetDirectory); + registry->Register(SetDirectory); + registry->Register(GetFilename); + registry->Register(SetFilename); + registry->Register(GetSignal); + registry->Register(SetSignal); + registry->Register(ShouldReportOnFatalError); + registry->Register(SetReportOnFatalError); + registry->Register(ShouldReportOnSignal); + registry->Register(SetReportOnSignal); + registry->Register(ShouldReportOnUncaughtException); + registry->Register(SetReportOnUncaughtException); +} + } // namespace report NODE_MODULE_CONTEXT_AWARE_INTERNAL(report, report::Initialize) +NODE_MODULE_EXTERNAL_REFERENCE(report, report::RegisterExternalReferences) diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 7ec3c66a78bb95..da52f5cee01062 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -22,12 +22,13 @@ #include "pipe_wrap.h" #include "async_wrap.h" +#include "connect_wrap.h" #include "connection_wrap.h" #include "env-inl.h" #include "handle_wrap.h" #include "node.h" #include "node_buffer.h" -#include "connect_wrap.h" +#include "node_external_reference.h" #include "stream_base-inl.h" #include "stream_wrap.h" #include "util-inl.h" @@ -104,6 +105,17 @@ void PipeWrap::Initialize(Local target, constants).Check(); } +void PipeWrap::RegisterExternalReferences(ExternalReferenceRegistry* registry) { + registry->Register(New); + registry->Register(Bind); + registry->Register(Listen); + registry->Register(Connect); + registry->Register(Open); +#ifdef _WIN32 + registry->Register(SetPendingInstances); +#endif + registry->Register(Fchmod); +} void PipeWrap::New(const FunctionCallbackInfo& args) { // This constructor should not be exposed to public javascript. @@ -236,3 +248,5 @@ void PipeWrap::Connect(const FunctionCallbackInfo& args) { } // namespace node NODE_MODULE_CONTEXT_AWARE_INTERNAL(pipe_wrap, node::PipeWrap::Initialize) +NODE_MODULE_EXTERNAL_REFERENCE(pipe_wrap, + node::PipeWrap::RegisterExternalReferences) diff --git a/src/pipe_wrap.h b/src/pipe_wrap.h index 53008b0d165044..c0722b63d85372 100644 --- a/src/pipe_wrap.h +++ b/src/pipe_wrap.h @@ -29,6 +29,7 @@ namespace node { +class ExternalReferenceRegistry; class Environment; class PipeWrap : public ConnectionWrap { @@ -47,6 +48,7 @@ class PipeWrap : public ConnectionWrap { v8::Local context, void* priv); + static void RegisterExternalReferences(ExternalReferenceRegistry* registry); SET_NO_MEMORY_INFO() SET_MEMORY_INFO_NAME(PipeWrap) SET_SELF_SIZE(PipeWrap) diff --git a/src/signal_wrap.cc b/src/signal_wrap.cc index e8a1500d2e9961..df7f94eeec8451 100644 --- a/src/signal_wrap.cc +++ b/src/signal_wrap.cc @@ -22,6 +22,7 @@ #include "async_wrap-inl.h" #include "env-inl.h" #include "handle_wrap.h" +#include "node_external_reference.h" #include "node_process-inl.h" #include "util-inl.h" #include "v8.h" @@ -62,6 +63,12 @@ class SignalWrap : public HandleWrap { env->SetConstructorFunction(target, "Signal", constructor); } + static void RegisterExternalReferences(ExternalReferenceRegistry* registry) { + registry->Register(New); + registry->Register(Start); + registry->Register(Stop); + } + SET_NO_MEMORY_INFO() SET_MEMORY_INFO_NAME(SignalWrap) SET_SELF_SIZE(SignalWrap) @@ -167,3 +174,5 @@ bool HasSignalJSHandler(int signum) { NODE_MODULE_CONTEXT_AWARE_INTERNAL(signal_wrap, node::SignalWrap::Initialize) +NODE_MODULE_EXTERNAL_REFERENCE(signal_wrap, + node::SignalWrap::RegisterExternalReferences) diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index 78d20f912b4cdb..2275167ad0eeb6 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -106,6 +106,10 @@ void LibuvStreamWrap::Initialize(Local target, void LibuvStreamWrap::RegisterExternalReferences( ExternalReferenceRegistry* registry) { registry->Register(IsConstructCallCallback); + registry->Register(GetWriteQueueSize); + registry->Register(SetBlocking); + // TODO(joyee): StreamBase::RegisterExternalReferences() is called somewhere + // else but we may want to do it here too and guard it with a static flag. } LibuvStreamWrap::LibuvStreamWrap(Environment* env, diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index cd7174984e2e36..84b18a1592d93c 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -21,12 +21,13 @@ #include "tcp_wrap.h" +#include "connect_wrap.h" #include "connection_wrap.h" #include "env-inl.h" #include "handle_wrap.h" #include "node_buffer.h" +#include "node_external_reference.h" #include "node_internals.h" -#include "connect_wrap.h" #include "stream_base-inl.h" #include "stream_wrap.h" #include "util-inl.h" @@ -120,6 +121,23 @@ void TCPWrap::Initialize(Local target, constants).Check(); } +void TCPWrap::RegisterExternalReferences(ExternalReferenceRegistry* registry) { + registry->Register(New); + registry->Register(Open); + registry->Register(Bind); + registry->Register(Listen); + registry->Register(Connect); + registry->Register(Bind6); + registry->Register(Connect6); + + registry->Register(GetSockOrPeerName); + registry->Register(GetSockOrPeerName); + registry->Register(SetNoDelay); + registry->Register(SetKeepAlive); +#ifdef _WIN32 + registry->Register(SetSimultaneousAccepts); +#endif +} void TCPWrap::New(const FunctionCallbackInfo& args) { // This constructor should not be exposed to public javascript. @@ -393,3 +411,5 @@ Local AddressToJS(Environment* env, } // namespace node NODE_MODULE_CONTEXT_AWARE_INTERNAL(tcp_wrap, node::TCPWrap::Initialize) +NODE_MODULE_EXTERNAL_REFERENCE(tcp_wrap, + node::TCPWrap::RegisterExternalReferences) diff --git a/src/tcp_wrap.h b/src/tcp_wrap.h index 0099eedb4bc629..3abf4ded19fd7c 100644 --- a/src/tcp_wrap.h +++ b/src/tcp_wrap.h @@ -29,6 +29,7 @@ namespace node { +class ExternalReferenceRegistry; class Environment; class TCPWrap : public ConnectionWrap { @@ -45,6 +46,7 @@ class TCPWrap : public ConnectionWrap { v8::Local unused, v8::Local context, void* priv); + static void RegisterExternalReferences(ExternalReferenceRegistry* registry); SET_NO_MEMORY_INFO() SET_SELF_SIZE(TCPWrap) diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index e9c7eb37a6621d..ca8c9356afe276 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -24,6 +24,7 @@ #include "env-inl.h" #include "handle_wrap.h" #include "node_buffer.h" +#include "node_external_reference.h" #include "stream_base-inl.h" #include "stream_wrap.h" #include "util-inl.h" @@ -40,6 +41,13 @@ using v8::Object; using v8::String; using v8::Value; +void TTYWrap::RegisterExternalReferences(ExternalReferenceRegistry* registry) { + registry->Register(New); + registry->Register(GetWindowSize); + registry->Register(SetRawMode); + registry->Register(IsTTY); +} + void TTYWrap::Initialize(Local target, Local unused, Local context, @@ -146,3 +154,5 @@ TTYWrap::TTYWrap(Environment* env, } // namespace node NODE_MODULE_CONTEXT_AWARE_INTERNAL(tty_wrap, node::TTYWrap::Initialize) +NODE_MODULE_EXTERNAL_REFERENCE(tty_wrap, + node::TTYWrap::RegisterExternalReferences) diff --git a/src/tty_wrap.h b/src/tty_wrap.h index 84e1fbb74d3384..629f187d747289 100644 --- a/src/tty_wrap.h +++ b/src/tty_wrap.h @@ -30,6 +30,7 @@ namespace node { class Environment; +class ExternalReferenceRegistry; class TTYWrap : public LibuvStreamWrap { public: @@ -37,6 +38,7 @@ class TTYWrap : public LibuvStreamWrap { v8::Local unused, v8::Local context, void* priv); + static void RegisterExternalReferences(ExternalReferenceRegistry* registry); SET_NO_MEMORY_INFO() SET_MEMORY_INFO_NAME(TTYWrap)