@@ -106,22 +106,33 @@ inline void StreamResource::RemoveStreamListener(StreamListener* listener) {
106
106
listener->previous_listener_ = nullptr ;
107
107
}
108
108
109
-
110
109
inline uv_buf_t StreamResource::EmitAlloc (size_t suggested_size) {
110
+ #ifdef DEBUG
111
+ v8::SealHandleScope handle_scope (v8::Isolate::GetCurrent ());
112
+ #endif
111
113
return listener_->OnStreamAlloc (suggested_size);
112
114
}
113
115
114
116
inline void StreamResource::EmitRead (ssize_t nread, const uv_buf_t & buf) {
117
+ #ifdef DEBUG
118
+ v8::SealHandleScope handle_scope (v8::Isolate::GetCurrent ());
119
+ #endif
115
120
if (nread > 0 )
116
121
bytes_read_ += static_cast <uint64_t >(nread);
117
122
listener_->OnStreamRead (nread, buf);
118
123
}
119
124
120
125
inline void StreamResource::EmitAfterWrite (WriteWrap* w, int status) {
126
+ #ifdef DEBUG
127
+ v8::SealHandleScope handle_scope (v8::Isolate::GetCurrent ());
128
+ #endif
121
129
listener_->OnStreamAfterWrite (w, status);
122
130
}
123
131
124
132
inline void StreamResource::EmitAfterShutdown (ShutdownWrap* w, int status) {
133
+ #ifdef DEBUG
134
+ v8::SealHandleScope handle_scope (v8::Isolate::GetCurrent ());
135
+ #endif
125
136
listener_->OnStreamAfterShutdown (w, status);
126
137
}
127
138
@@ -133,29 +144,6 @@ inline Environment* StreamBase::stream_env() const {
133
144
return env_;
134
145
}
135
146
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
-
159
147
inline int StreamBase::Shutdown (v8::Local<v8::Object> req_wrap_obj) {
160
148
Environment* env = stream_env ();
161
149
if (req_wrap_obj.IsEmpty ()) {
@@ -387,7 +375,8 @@ void StreamBase::JSMethod(const FunctionCallbackInfo<Value>& args) {
387
375
388
376
389
377
inline void ShutdownWrap::OnDone (int status) {
390
- stream ()->AfterShutdown (this , status);
378
+ stream ()->EmitAfterShutdown (this , status);
379
+ Dispose ();
391
380
}
392
381
393
382
inline void WriteWrap::SetAllocatedStorage (char * data, size_t size) {
@@ -405,7 +394,8 @@ inline size_t WriteWrap::StorageSize() const {
405
394
}
406
395
407
396
inline void WriteWrap::OnDone (int status) {
408
- stream ()->AfterWrite (this , status);
397
+ stream ()->EmitAfterWrite (this , status);
398
+ Dispose ();
409
399
}
410
400
411
401
inline void StreamReq::Done (int status, const char * error_str) {
0 commit comments