diff --git a/src/node_http2.cc b/src/node_http2.cc index 835e15587ff64d..96a0fa631e0b3e 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -9,12 +9,14 @@ #include "node_mem-inl.h" #include "node_perf.h" #include "node_revert.h" +#include "stream_base-inl.h" #include "util-inl.h" #include namespace node { +using v8::Array; using v8::ArrayBuffer; using v8::ArrayBufferView; using v8::BackingStore; @@ -22,15 +24,23 @@ using v8::Boolean; using v8::Context; using v8::Float64Array; using v8::Function; +using v8::FunctionCallbackInfo; +using v8::FunctionTemplate; +using v8::HandleScope; using v8::Integer; +using v8::Isolate; +using v8::Local; +using v8::MaybeLocal; using v8::NewStringType; using v8::Number; +using v8::Object; using v8::ObjectTemplate; using v8::String; using v8::Uint32; using v8::Uint32Array; using v8::Uint8Array; using v8::Undefined; +using v8::Value; using node::performance::PerformanceEntry; namespace http2 { diff --git a/src/node_http2.h b/src/node_http2.h index e0a4e40449150e..96ee839f037059 100644 --- a/src/node_http2.h +++ b/src/node_http2.h @@ -11,7 +11,7 @@ #include "node_http_common.h" #include "node_mem.h" #include "node_perf.h" -#include "stream_base-inl.h" +#include "stream_base.h" #include "string_bytes.h" #include @@ -20,13 +20,6 @@ namespace node { namespace http2 { -using v8::Array; -using v8::Context; -using v8::Isolate; -using v8::MaybeLocal; - -using performance::PerformanceEntry; - // We strictly limit the number of outstanding unacknowledged PINGS a user // may send in order to prevent abuse. The current default cap is 10. The // user may set a different limit using a per Http2Session configuration @@ -169,7 +162,7 @@ class Http2Scope { private: Http2Session* session_ = nullptr; - Local session_handle_; + v8::Local session_handle_; }; // The Http2Options class is used to parse the options object passed in to @@ -240,9 +233,9 @@ class Http2Options { class Http2Priority { public: Http2Priority(Environment* env, - Local parent, - Local weight, - Local exclusive); + v8::Local parent, + v8::Local weight, + v8::Local exclusive); nghttp2_priority_spec* operator*() { return &spec; @@ -410,15 +403,15 @@ class Http2Stream : public AsyncWrap, std::string diagnostic_name() const override; // JavaScript API - static void GetID(const FunctionCallbackInfo& args); - static void Destroy(const FunctionCallbackInfo& args); - static void Priority(const FunctionCallbackInfo& args); - static void PushPromise(const FunctionCallbackInfo& args); - static void RefreshState(const FunctionCallbackInfo& args); - static void Info(const FunctionCallbackInfo& args); - static void Trailers(const FunctionCallbackInfo& args); - static void Respond(const FunctionCallbackInfo& args); - static void RstStream(const FunctionCallbackInfo& args); + static void GetID(const v8::FunctionCallbackInfo& args); + static void Destroy(const v8::FunctionCallbackInfo& args); + static void Priority(const v8::FunctionCallbackInfo& args); + static void PushPromise(const v8::FunctionCallbackInfo& args); + static void RefreshState(const v8::FunctionCallbackInfo& args); + static void Info(const v8::FunctionCallbackInfo& args); + static void Trailers(const v8::FunctionCallbackInfo& args); + static void Respond(const v8::FunctionCallbackInfo& args); + static void RstStream(const v8::FunctionCallbackInfo& args); class Provider; @@ -540,7 +533,7 @@ class Http2Session : public AsyncWrap, public mem::NgLibMemoryManager { public: Http2Session(Environment* env, - Local wrap, + v8::Local wrap, nghttp2_session_type type = NGHTTP2_SESSION_SERVER); ~Http2Session() override; @@ -555,7 +548,7 @@ class Http2Session : public AsyncWrap, void Close(uint32_t code = NGHTTP2_NO_ERROR, bool socket_closed = false); - void Consume(Local stream); + void Consume(v8::Local stream); void Goaway(uint32_t code, int32_t lastStreamID, const uint8_t* data, size_t len); void AltSvc(int32_t id, @@ -652,21 +645,21 @@ class Http2Session : public AsyncWrap, void DecreaseAllocatedSize(size_t size); // The JavaScript API - static void New(const FunctionCallbackInfo& args); - static void Consume(const FunctionCallbackInfo& args); - static void Destroy(const FunctionCallbackInfo& args); - static void Settings(const FunctionCallbackInfo& args); - static void Request(const FunctionCallbackInfo& args); - static void SetNextStreamID(const FunctionCallbackInfo& args); - static void Goaway(const FunctionCallbackInfo& args); - static void UpdateChunksSent(const FunctionCallbackInfo& args); - static void RefreshState(const FunctionCallbackInfo& args); - static void Ping(const FunctionCallbackInfo& args); - static void AltSvc(const FunctionCallbackInfo& args); - static void Origin(const FunctionCallbackInfo& args); + static void New(const v8::FunctionCallbackInfo& args); + static void Consume(const v8::FunctionCallbackInfo& args); + static void Destroy(const v8::FunctionCallbackInfo& args); + static void Settings(const v8::FunctionCallbackInfo& args); + static void Request(const v8::FunctionCallbackInfo& args); + static void SetNextStreamID(const v8::FunctionCallbackInfo& args); + static void Goaway(const v8::FunctionCallbackInfo& args); + static void UpdateChunksSent(const v8::FunctionCallbackInfo& args); + static void RefreshState(const v8::FunctionCallbackInfo& args); + static void Ping(const v8::FunctionCallbackInfo& args); + static void AltSvc(const v8::FunctionCallbackInfo& args); + static void Origin(const v8::FunctionCallbackInfo& args); template - static void RefreshSettings(const FunctionCallbackInfo& args); + static void RefreshSettings(const v8::FunctionCallbackInfo& args); uv_loop_t* event_loop() const { return env()->event_loop(); @@ -877,15 +870,16 @@ class Http2Session : public AsyncWrap, friend class Http2StreamListener; }; -class Http2SessionPerformanceEntry : public PerformanceEntry { +class Http2SessionPerformanceEntry : public performance::PerformanceEntry { public: Http2SessionPerformanceEntry( Environment* env, const Http2Session::Statistics& stats, nghttp2_session_type type) : - PerformanceEntry(env, "Http2Session", "http2", - stats.start_time, - stats.end_time), + performance::PerformanceEntry( + env, "Http2Session", "http2", + stats.start_time, + stats.end_time), ping_rtt_(stats.ping_rtt), data_sent_(stats.data_sent), data_received_(stats.data_received), @@ -906,8 +900,8 @@ class Http2SessionPerformanceEntry : public PerformanceEntry { double stream_average_duration() const { return stream_average_duration_; } nghttp2_session_type type() const { return session_type_; } - void Notify(Local obj) { - PerformanceEntry::Notify(env(), kind(), obj); + void Notify(v8::Local obj) { + performance::PerformanceEntry::Notify(env(), kind(), obj); } private: @@ -922,15 +916,17 @@ class Http2SessionPerformanceEntry : public PerformanceEntry { nghttp2_session_type session_type_; }; -class Http2StreamPerformanceEntry : public PerformanceEntry { +class Http2StreamPerformanceEntry + : public performance::PerformanceEntry { public: Http2StreamPerformanceEntry( Environment* env, int32_t id, const Http2Stream::Statistics& stats) : - PerformanceEntry(env, "Http2Stream", "http2", - stats.start_time, - stats.end_time), + performance::PerformanceEntry( + env, "Http2Stream", "http2", + stats.start_time, + stats.end_time), id_(id), first_header_(stats.first_header), first_byte_(stats.first_byte), @@ -945,8 +941,8 @@ class Http2StreamPerformanceEntry : public PerformanceEntry { uint64_t sent_bytes() const { return sent_bytes_; } uint64_t received_bytes() const { return received_bytes_; } - void Notify(Local obj) { - PerformanceEntry::Notify(env(), kind(), obj); + void Notify(v8::Local obj) { + performance::PerformanceEntry::Notify(env(), kind(), obj); } private: @@ -999,7 +995,7 @@ class Http2Session::Http2Settings : public AsyncWrap { void Done(bool ack); // Returns a Buffer instance with the serialized SETTINGS payload - Local Pack(); + v8::Local Pack(); // Resets the default values in the settings buffer static void RefreshDefaults(Environment* env); @@ -1019,9 +1015,9 @@ class Http2Session::Http2Settings : public AsyncWrap { class Origins { public: - Origins(Isolate* isolate, - Local context, - Local origin_string, + Origins(v8::Isolate* isolate, + v8::Local context, + v8::Local origin_string, size_t origin_count); ~Origins() = default; diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index 27a9a01c7c2170..d365c550ce4838 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -11,18 +11,13 @@ namespace node { -using v8::Signature; -using v8::FunctionCallbackInfo; -using v8::FunctionTemplate; -using v8::HandleScope; -using v8::Local; -using v8::Object; -using v8::PropertyAttribute; -using v8::PropertyCallbackInfo; -using v8::String; -using v8::Value; - -inline void StreamReq::AttachToObject(v8::Local req_wrap_obj) { +StreamReq::StreamReq( + StreamBase* stream, + v8::Local req_wrap_obj) : stream_(stream) { + AttachToObject(req_wrap_obj); +} + +void StreamReq::AttachToObject(v8::Local req_wrap_obj) { CHECK_EQ(req_wrap_obj->GetAlignedPointerFromInternalField( StreamReq::kStreamReqField), nullptr); @@ -30,56 +25,38 @@ inline void StreamReq::AttachToObject(v8::Local req_wrap_obj) { StreamReq::kStreamReqField, this); } -inline StreamReq* StreamReq::FromObject(v8::Local req_wrap_obj) { +StreamReq* StreamReq::FromObject(v8::Local req_wrap_obj) { return static_cast( req_wrap_obj->GetAlignedPointerFromInternalField( StreamReq::kStreamReqField)); } -inline void StreamReq::Dispose() { +void StreamReq::Dispose() { + std::unique_ptr ptr(this); object()->SetAlignedPointerInInternalField( StreamReq::kStreamReqField, nullptr); - delete this; } -inline v8::Local StreamReq::object() { +v8::Local StreamReq::object() { return GetAsyncWrap()->object(); } -inline StreamListener::~StreamListener() { - if (stream_ != nullptr) - stream_->RemoveStreamListener(this); -} - -inline void StreamListener::PassReadErrorToPreviousListener(ssize_t nread) { - CHECK_NOT_NULL(previous_listener_); - previous_listener_->OnStreamRead(nread, uv_buf_init(nullptr, 0)); -} +ShutdownWrap::ShutdownWrap( + StreamBase* stream, + v8::Local req_wrap_obj) + : StreamReq(stream, req_wrap_obj) { } -inline void StreamListener::OnStreamAfterShutdown(ShutdownWrap* w, int status) { - CHECK_NOT_NULL(previous_listener_); - previous_listener_->OnStreamAfterShutdown(w, status); -} +WriteWrap::WriteWrap( + StreamBase* stream, + v8::Local req_wrap_obj) + : StreamReq(stream, req_wrap_obj) { } -inline void StreamListener::OnStreamAfterWrite(WriteWrap* w, int status) { +void StreamListener::PassReadErrorToPreviousListener(ssize_t nread) { CHECK_NOT_NULL(previous_listener_); - previous_listener_->OnStreamAfterWrite(w, status); -} - -inline StreamResource::~StreamResource() { - while (listener_ != nullptr) { - StreamListener* listener = listener_; - listener->OnStreamDestroy(); - // Remove the listener if it didn’t remove itself. This makes the logic - // in `OnStreamDestroy()` implementations easier, because they - // may call generic cleanup functions which can just remove the - // listener unconditionally. - if (listener == listener_) - RemoveStreamListener(listener_); - } + previous_listener_->OnStreamRead(nread, uv_buf_init(nullptr, 0)); } -inline void StreamResource::PushStreamListener(StreamListener* listener) { +void StreamResource::PushStreamListener(StreamListener* listener) { CHECK_NOT_NULL(listener); CHECK_NULL(listener->stream_); @@ -89,7 +66,7 @@ inline void StreamResource::PushStreamListener(StreamListener* listener) { listener_ = listener; } -inline void StreamResource::RemoveStreamListener(StreamListener* listener) { +void StreamResource::RemoveStreamListener(StreamListener* listener) { CHECK_NOT_NULL(listener); StreamListener* previous; @@ -113,45 +90,41 @@ inline void StreamResource::RemoveStreamListener(StreamListener* listener) { listener->previous_listener_ = nullptr; } -inline uv_buf_t StreamResource::EmitAlloc(size_t suggested_size) { +uv_buf_t StreamResource::EmitAlloc(size_t suggested_size) { DebugSealHandleScope handle_scope(v8::Isolate::GetCurrent()); return listener_->OnStreamAlloc(suggested_size); } -inline void StreamResource::EmitRead(ssize_t nread, const uv_buf_t& buf) { +void StreamResource::EmitRead(ssize_t nread, const uv_buf_t& buf) { DebugSealHandleScope handle_scope(v8::Isolate::GetCurrent()); if (nread > 0) bytes_read_ += static_cast(nread); listener_->OnStreamRead(nread, buf); } -inline void StreamResource::EmitAfterWrite(WriteWrap* w, int status) { +void StreamResource::EmitAfterWrite(WriteWrap* w, int status) { DebugSealHandleScope handle_scope(v8::Isolate::GetCurrent()); listener_->OnStreamAfterWrite(w, status); } -inline void StreamResource::EmitAfterShutdown(ShutdownWrap* w, int status) { +void StreamResource::EmitAfterShutdown(ShutdownWrap* w, int status) { DebugSealHandleScope handle_scope(v8::Isolate::GetCurrent()); listener_->OnStreamAfterShutdown(w, status); } -inline void StreamResource::EmitWantsWrite(size_t suggested_size) { +void StreamResource::EmitWantsWrite(size_t suggested_size) { DebugSealHandleScope handle_scope(v8::Isolate::GetCurrent()); listener_->OnStreamWantsWrite(suggested_size); } -inline StreamBase::StreamBase(Environment* env) : env_(env) { +StreamBase::StreamBase(Environment* env) : env_(env) { PushStreamListener(&default_listener_); } -inline Environment* StreamBase::stream_env() const { - return env_; -} - -inline int StreamBase::Shutdown(v8::Local req_wrap_obj) { +int StreamBase::Shutdown(v8::Local req_wrap_obj) { Environment* env = stream_env(); - HandleScope handle_scope(env->isolate()); + v8::HandleScope handle_scope(env->isolate()); if (req_wrap_obj.IsEmpty()) { if (!env->shutdown_wrap_template() @@ -181,7 +154,7 @@ inline int StreamBase::Shutdown(v8::Local req_wrap_obj) { return err; } -inline StreamWriteResult StreamBase::Write( +StreamWriteResult StreamBase::Write( uv_buf_t* bufs, size_t count, uv_stream_t* send_handle, @@ -201,7 +174,7 @@ inline StreamWriteResult StreamBase::Write( } } - HandleScope handle_scope(env->isolate()); + v8::HandleScope handle_scope(env->isolate()); if (req_wrap_obj.IsEmpty()) { if (!env->write_wrap_template() @@ -244,11 +217,6 @@ SimpleShutdownWrap::SimpleShutdownWrap( AsyncWrap::PROVIDER_SHUTDOWNWRAP) { } -inline ShutdownWrap* StreamBase::CreateShutdownWrap( - v8::Local object) { - return new SimpleShutdownWrap(this, object); -} - template SimpleWriteWrap::SimpleWriteWrap( StreamBase* stream, @@ -259,17 +227,12 @@ SimpleWriteWrap::SimpleWriteWrap( AsyncWrap::PROVIDER_WRITEWRAP) { } -inline WriteWrap* StreamBase::CreateWriteWrap( - v8::Local object) { - return new SimpleWriteWrap(this, object); -} - -inline void StreamBase::AttachToObject(v8::Local obj) { +void StreamBase::AttachToObject(v8::Local obj) { obj->SetAlignedPointerInInternalField( StreamBase::kStreamBaseField, this); } -inline StreamBase* StreamBase::FromObject(v8::Local obj) { +StreamBase* StreamBase::FromObject(v8::Local obj) { if (obj->GetAlignedPointerFromInternalField(StreamBase::kSlot) == nullptr) return nullptr; @@ -278,23 +241,12 @@ inline StreamBase* StreamBase::FromObject(v8::Local obj) { StreamBase::kStreamBaseField)); } - -inline void ShutdownWrap::OnDone(int status) { - stream()->EmitAfterShutdown(this, status); - Dispose(); -} - -inline void WriteWrap::SetAllocatedStorage(AllocatedBuffer&& storage) { +void WriteWrap::SetAllocatedStorage(AllocatedBuffer&& storage) { CHECK_NULL(storage_.data()); storage_ = std::move(storage); } -inline void WriteWrap::OnDone(int status) { - stream()->EmitAfterWrite(this, status); - Dispose(); -} - -inline void StreamReq::Done(int status, const char* error_str) { +void StreamReq::Done(int status, const char* error_str) { AsyncWrap* async_wrap = GetAsyncWrap(); Environment* env = async_wrap->env(); if (error_str != nullptr) { @@ -307,14 +259,13 @@ inline void StreamReq::Done(int status, const char* error_str) { OnDone(status); } -inline void StreamReq::ResetObject(v8::Local obj) { +void StreamReq::ResetObject(v8::Local obj) { DCHECK_GT(obj->InternalFieldCount(), StreamReq::kStreamReqField); obj->SetAlignedPointerInInternalField(StreamReq::kSlot, nullptr); obj->SetAlignedPointerInInternalField(StreamReq::kStreamReqField, nullptr); } - } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS diff --git a/src/stream_base.cc b/src/stream_base.cc index 28a3bf65fc0178..63b06378f7c127 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -17,18 +17,23 @@ namespace node { using v8::Array; using v8::ArrayBuffer; +using v8::ConstructorBehavior; using v8::Context; using v8::DontDelete; using v8::DontEnum; using v8::External; using v8::Function; using v8::FunctionCallbackInfo; +using v8::FunctionTemplate; using v8::HandleScope; using v8::Integer; using v8::Local; using v8::MaybeLocal; using v8::Object; +using v8::PropertyAttribute; using v8::ReadOnly; +using v8::SideEffectType; +using v8::Signature; using v8::String; using v8::Value; @@ -370,8 +375,8 @@ void StreamBase::AddMethod(Environment* env, Local templ = env->NewFunctionTemplate(stream_method, signature, - v8::ConstructorBehavior::kThrow, - v8::SideEffectType::kHasNoSideEffect); + ConstructorBehavior::kThrow, + SideEffectType::kHasNoSideEffect); t->PrototypeTemplate()->SetAccessorProperty( string, templ, Local(), attributes); } @@ -567,5 +572,52 @@ void ReportWritesToJSStreamListener::OnStreamAfterShutdown( OnStreamAfterReqFinished(req_wrap, status); } +void ShutdownWrap::OnDone(int status) { + stream()->EmitAfterShutdown(this, status); + Dispose(); +} + +void WriteWrap::OnDone(int status) { + stream()->EmitAfterWrite(this, status); + Dispose(); +} + +StreamListener::~StreamListener() { + if (stream_ != nullptr) + stream_->RemoveStreamListener(this); +} + +void StreamListener::OnStreamAfterShutdown(ShutdownWrap* w, int status) { + CHECK_NOT_NULL(previous_listener_); + previous_listener_->OnStreamAfterShutdown(w, status); +} + +void StreamListener::OnStreamAfterWrite(WriteWrap* w, int status) { + CHECK_NOT_NULL(previous_listener_); + previous_listener_->OnStreamAfterWrite(w, status); +} + +StreamResource::~StreamResource() { + while (listener_ != nullptr) { + StreamListener* listener = listener_; + listener->OnStreamDestroy(); + // Remove the listener if it didn’t remove itself. This makes the logic + // in `OnStreamDestroy()` implementations easier, because they + // may call generic cleanup functions which can just remove the + // listener unconditionally. + if (listener == listener_) + RemoveStreamListener(listener_); + } +} + +ShutdownWrap* StreamBase::CreateShutdownWrap( + Local object) { + return new SimpleShutdownWrap(this, object); +} + +WriteWrap* StreamBase::CreateWriteWrap( + Local object) { + return new SimpleWriteWrap(this, object); +} } // namespace node diff --git a/src/stream_base.h b/src/stream_base.h index 15b83ec91f6387..c0c3c0f6c4ac55 100644 --- a/src/stream_base.h +++ b/src/stream_base.h @@ -38,21 +38,20 @@ class StreamReq { kInternalFieldCount }; - explicit StreamReq(StreamBase* stream, - v8::Local req_wrap_obj) : stream_(stream) { - AttachToObject(req_wrap_obj); - } + inline explicit StreamReq( + StreamBase* stream, + v8::Local req_wrap_obj); virtual ~StreamReq() = default; virtual AsyncWrap* GetAsyncWrap() = 0; - v8::Local object(); + inline v8::Local object(); - void Done(int status, const char* error_str = nullptr); - void Dispose(); + inline void Done(int status, const char* error_str = nullptr); + inline void Dispose(); - inline StreamBase* stream() const { return stream_; } + StreamBase* stream() const { return stream_; } - static StreamReq* FromObject(v8::Local req_wrap_obj); + static inline StreamReq* FromObject(v8::Local req_wrap_obj); // Sets all internal fields of `req_wrap_obj` to `nullptr`. // This is what the `WriteWrap` and `ShutdownWrap` JS constructors do, @@ -64,7 +63,7 @@ class StreamReq { protected: virtual void OnDone(int status) = 0; - void AttachToObject(v8::Local req_wrap_obj); + inline void AttachToObject(v8::Local req_wrap_obj); private: StreamBase* const stream_; @@ -72,9 +71,9 @@ class StreamReq { class ShutdownWrap : public StreamReq { public: - ShutdownWrap(StreamBase* stream, - v8::Local req_wrap_obj) - : StreamReq(stream, req_wrap_obj) { } + inline ShutdownWrap( + StreamBase* stream, + v8::Local req_wrap_obj); // Call stream()->EmitAfterShutdown() and dispose of this request wrap. void OnDone(int status) override; @@ -82,11 +81,11 @@ class ShutdownWrap : public StreamReq { class WriteWrap : public StreamReq { public: - void SetAllocatedStorage(AllocatedBuffer&& storage); + inline void SetAllocatedStorage(AllocatedBuffer&& storage); - WriteWrap(StreamBase* stream, - v8::Local req_wrap_obj) - : StreamReq(stream, req_wrap_obj) { } + inline WriteWrap( + StreamBase* stream, + v8::Local req_wrap_obj); // Call stream()->EmitAfterWrite() and dispose of this request wrap. void OnDone(int status) override; @@ -150,14 +149,14 @@ class StreamListener { virtual void OnStreamDestroy() {} // The stream this is currently associated with, or nullptr if there is none. - inline StreamResource* stream() { return stream_; } + StreamResource* stream() const { return stream_; } protected: // Pass along a read error to the `StreamListener` instance that was active // before this one. For example, a protocol parser does not care about read // errors and may instead want to let the original handler // (e.g. the JS handler) take care of the situation. - void PassReadErrorToPreviousListener(ssize_t nread); + inline void PassReadErrorToPreviousListener(ssize_t nread); StreamResource* stream_ = nullptr; StreamListener* previous_listener_ = nullptr; @@ -254,23 +253,25 @@ class StreamResource { // Transfer ownership of this stream to `listener`. The previous listener // will not receive any more callbacks while the new listener was active. - void PushStreamListener(StreamListener* listener); + inline void PushStreamListener(StreamListener* listener); // Remove a listener, and, if this was the currently active one, // transfer ownership back to the previous listener. - void RemoveStreamListener(StreamListener* listener); + inline void RemoveStreamListener(StreamListener* listener); protected: // Call the current listener's OnStreamAlloc() method. - uv_buf_t EmitAlloc(size_t suggested_size); + inline uv_buf_t EmitAlloc(size_t suggested_size); // Call the current listener's OnStreamRead() method and update the // stream's read byte counter. - void EmitRead(ssize_t nread, const uv_buf_t& buf = uv_buf_init(nullptr, 0)); + inline void EmitRead( + ssize_t nread, + const uv_buf_t& buf = uv_buf_init(nullptr, 0)); // Call the current listener's OnStreamAfterWrite() method. - void EmitAfterWrite(WriteWrap* w, int status); + inline void EmitAfterWrite(WriteWrap* w, int status); // Call the current listener's OnStreamAfterShutdown() method. - void EmitAfterShutdown(ShutdownWrap* w, int status); + inline void EmitAfterShutdown(ShutdownWrap* w, int status); // Call the current listener's OnStreamWantsWrite() method. - void EmitWantsWrite(size_t suggested_size); + inline void EmitWantsWrite(size_t suggested_size); StreamListener* listener_ = nullptr; uint64_t bytes_read_ = 0; @@ -310,13 +311,14 @@ class StreamBase : public StreamResource { // This is named `stream_env` to avoid name clashes, because a lot of // subclasses are also `BaseObject`s. - Environment* stream_env() const; + Environment* stream_env() const { return env_; } // Shut down the current stream. This request can use an existing // ShutdownWrap object (that was created in JS), or a new one will be created. // Returns 1 in case of a synchronous completion, 0 in case of asynchronous // completion, and a libuv error case in case of synchronous failure. - int Shutdown(v8::Local req_wrap_obj = v8::Local()); + inline int Shutdown( + v8::Local req_wrap_obj = v8::Local()); // Write data to the current stream. This request can use an existing // WriteWrap object (that was created in JS), or a new one will be created. @@ -324,7 +326,7 @@ class StreamBase : public StreamResource { // asynchronously using `DoWrite()`. // If the return value indicates a synchronous completion, no callback will // be invoked. - StreamWriteResult Write( + inline StreamWriteResult Write( uv_buf_t* bufs, size_t count, uv_stream_t* send_handle = nullptr, @@ -341,10 +343,10 @@ class StreamBase : public StreamResource { virtual AsyncWrap* GetAsyncWrap() = 0; virtual v8::Local GetObject(); - static StreamBase* FromObject(v8::Local obj); + static inline StreamBase* FromObject(v8::Local obj); protected: - explicit StreamBase(Environment* env); + inline explicit StreamBase(Environment* env); // JS Methods int ReadStartJS(const v8::FunctionCallbackInfo& args); @@ -360,7 +362,7 @@ class StreamBase : public StreamResource { static void GetExternal(const v8::FunctionCallbackInfo& args); static void GetBytesRead(const v8::FunctionCallbackInfo& args); static void GetBytesWritten(const v8::FunctionCallbackInfo& args); - void AttachToObject(v8::Local obj); + inline void AttachToObject(v8::Local obj); template & args)> diff --git a/src/stream_pipe.cc b/src/stream_pipe.cc index 40b094ab5930a5..1bed4514eb8dd8 100644 --- a/src/stream_pipe.cc +++ b/src/stream_pipe.cc @@ -3,16 +3,18 @@ #include "node_buffer.h" #include "util-inl.h" +namespace node { + using v8::Context; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; +using v8::HandleScope; using v8::Local; using v8::Object; +using v8::String; using v8::Value; -namespace node { - StreamPipe::StreamPipe(StreamBase* source, StreamBase* sink, Local obj) diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index 7548516e477a36..cc0d046ec11f2d 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -46,8 +46,10 @@ using v8::HandleScope; using v8::Local; using v8::MaybeLocal; using v8::Object; +using v8::PropertyAttribute; using v8::ReadOnly; using v8::Signature; +using v8::String; using v8::Value; diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 39dcf532a9fb7a..b24c0df0c2bfe8 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -43,12 +43,14 @@ using v8::Exception; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; +using v8::HandleScope; using v8::Integer; using v8::Isolate; using v8::Local; using v8::Maybe; using v8::MaybeLocal; using v8::Object; +using v8::PropertyAttribute; using v8::ReadOnly; using v8::Signature; using v8::String;