@@ -106,22 +106,33 @@ inline void StreamResource::RemoveStreamListener(StreamListener* listener) {
106106 listener->previous_listener_ = nullptr ;
107107}
108108
109-
110109inline uv_buf_t StreamResource::EmitAlloc (size_t suggested_size) {
110+ #ifdef DEBUG
111+ v8::SealHandleScope handle_scope (v8::Isolate::GetCurrent ());
112+ #endif
111113 return listener_->OnStreamAlloc (suggested_size);
112114}
113115
114116inline void StreamResource::EmitRead (ssize_t nread, const uv_buf_t & buf) {
117+ #ifdef DEBUG
118+ v8::SealHandleScope handle_scope (v8::Isolate::GetCurrent ());
119+ #endif
115120 if (nread > 0 )
116121 bytes_read_ += static_cast <uint64_t >(nread);
117122 listener_->OnStreamRead (nread, buf);
118123}
119124
120125inline void StreamResource::EmitAfterWrite (WriteWrap* w, int status) {
126+ #ifdef DEBUG
127+ v8::SealHandleScope handle_scope (v8::Isolate::GetCurrent ());
128+ #endif
121129 listener_->OnStreamAfterWrite (w, status);
122130}
123131
124132inline void StreamResource::EmitAfterShutdown (ShutdownWrap* w, int status) {
133+ #ifdef DEBUG
134+ v8::SealHandleScope handle_scope (v8::Isolate::GetCurrent ());
135+ #endif
125136 listener_->OnStreamAfterShutdown (w, status);
126137}
127138
@@ -133,29 +144,6 @@ inline Environment* StreamBase::stream_env() const {
133144 return env_;
134145}
135146
136- inline void StreamBase::AfterWrite (WriteWrap* req_wrap, int status) {
137- AfterRequest (req_wrap, [&]() {
138- EmitAfterWrite (req_wrap, status);
139- });
140- }
141-
142- inline void StreamBase::AfterShutdown (ShutdownWrap* req_wrap, int status) {
143- AfterRequest (req_wrap, [&]() {
144- EmitAfterShutdown (req_wrap, status);
145- });
146- }
147-
148- template <typename Wrap, typename EmitEvent>
149- inline void StreamBase::AfterRequest (Wrap* req_wrap, EmitEvent emit) {
150- Environment* env = stream_env ();
151-
152- v8::HandleScope handle_scope (env->isolate ());
153- v8::Context::Scope context_scope (env->context ());
154-
155- emit ();
156- req_wrap->Dispose ();
157- }
158-
159147inline int StreamBase::Shutdown (v8::Local<v8::Object> req_wrap_obj) {
160148 Environment* env = stream_env ();
161149 if (req_wrap_obj.IsEmpty ()) {
@@ -387,7 +375,8 @@ void StreamBase::JSMethod(const FunctionCallbackInfo<Value>& args) {
387375
388376
389377inline void ShutdownWrap::OnDone (int status) {
390- stream ()->AfterShutdown (this , status);
378+ stream ()->EmitAfterShutdown (this , status);
379+ Dispose ();
391380}
392381
393382inline void WriteWrap::SetAllocatedStorage (char * data, size_t size) {
@@ -405,7 +394,8 @@ inline size_t WriteWrap::StorageSize() const {
405394}
406395
407396inline void WriteWrap::OnDone (int status) {
408- stream ()->AfterWrite (this , status);
397+ stream ()->EmitAfterWrite (this , status);
398+ Dispose ();
409399}
410400
411401inline void StreamReq::Done (int status, const char * error_str) {
0 commit comments