| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3ad7c1a commit 8695273
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1132,6 +1132,8 @@ void Http2StreamListener::OnStreamRead(ssize_t nread, const uv_buf_t& buf) { | |||
| 1132 | 1132 | Http2Stream* stream = static_cast<Http2Stream*>(stream_); | |
| 1133 | 1133 | Http2Session* session = stream->session(); | |
| 1134 | 1134 | Environment* env = stream->env(); | |
| 1135 | + HandleScope handle_scope(env->isolate()); | ||
| 1136 | + Context::Scope context_scope(env->context()); | ||
| 1135 | 1137 | ||
| 1136 | 1138 | if (nread < 0) { | |
| 1137 | 1139 | PassReadErrorToPreviousListener(nread); | |
@@ -1422,6 +1424,7 @@ void Http2Session::OnStreamAfterWrite(WriteWrap* w, int status) { | |||
| 1422 | 1424 | void Http2Session::MaybeScheduleWrite() { | |
| 1423 | 1425 | CHECK_EQ(flags_ & SESSION_STATE_WRITE_SCHEDULED, 0); | |
| 1424 | 1426 | if (session_ != nullptr && nghttp2_session_want_write(session_)) { | |
| 1427 | + HandleScope handle_scope(env()->isolate()); | ||
| 1425 | 1428 | DEBUG_HTTP2SESSION(this, "scheduling write"); | |
| 1426 | 1429 | flags_ |= SESSION_STATE_WRITE_SCHEDULED; | |
| 1427 | 1430 | env()->SetImmediate([](Environment* env, void* data) { | |
@@ -1632,6 +1635,8 @@ inline Http2Stream* Http2Session::SubmitRequest( | |||
| 1632 | 1635 | ||
| 1633 | 1636 | // Callback used to receive inbound data from the i/o stream | |
| 1634 | 1637 | void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf) { | |
| 1638 | + HandleScope handle_scope(env()->isolate()); | ||
| 1639 | + Context::Scope context_scope(env()->context()); | ||
| 1635 | 1640 | Http2Scope h2scope(this); | |
| 1636 | 1641 | CHECK_NE(stream_, nullptr); | |
| 1637 | 1642 | DEBUG_HTTP2SESSION2(this, "receiving %d bytes", nread); | |
@@ -1661,8 +1666,6 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf) { | |||
| 1661 | 1666 | CHECK_LE(static_cast<size_t>(nread), stream_buf_.len); | |
| 1662 | 1667 | ||
| 1663 | 1668 | Isolate* isolate = env()->isolate(); | |
| 1664 | - HandleScope scope(isolate); | ||
| 1665 | - Context::Scope context_scope(env()->context()); | ||
| 1666 | 1669 | ||
| 1667 | 1670 | // Create an array buffer for the read data. DATA frames will be emitted | |
| 1668 | 1671 | // as slices of this array buffer to avoid having to copy memory. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -387,6 +387,8 @@ void ReportWritesToJSStreamListener::OnStreamAfterReqFinished( | |||
| 387 | 387 | StreamBase* stream = static_cast<StreamBase*>(stream_); | |
| 388 | 388 | Environment* env = stream->stream_env(); | |
| 389 | 389 | AsyncWrap* async_wrap = req_wrap->GetAsyncWrap(); | |
| 390 | + HandleScope handle_scope(env->isolate()); | ||
| 391 | + Context::Scope context_scope(env->context()); | ||
| 390 | 392 | Local<Object> req_wrap_obj = async_wrap->object(); | |
| 391 | 393 | ||
| 392 | 394 | Local<Value> argv[] = { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,7 +61,8 @@ class ShutdownWrap : public StreamReq { | |||
| 61 | 61 | v8::Local<v8::Object> req_wrap_obj) | |
| 62 | 62 | : StreamReq(stream, req_wrap_obj) { } | |
| 63 | 63 | ||
| 64 | - void OnDone(int status) override; // Just calls stream()->AfterShutdown() | ||
| 64 | + // Call stream()->EmitAfterShutdown() and dispose of this request wrap. | ||
| 65 | + void OnDone(int status) override; | ||
| 65 | 66 | }; | |
| 66 | 67 | ||
| 67 | 68 | class WriteWrap : public StreamReq { | |
@@ -78,7 +79,8 @@ class WriteWrap : public StreamReq { | |||
| 78 | 79 | free(storage_); | |
| 79 | 80 | } | |
| 80 | 81 | ||
| 81 | - void OnDone(int status) override; // Just calls stream()->AfterWrite() | ||
| 82 | + // Call stream()->EmitAfterWrite() and dispose of this request wrap. | ||
| 83 | + void OnDone(int status) override; | ||
| 82 | 84 | ||
| 83 | 85 | private: | |
| 84 | 86 | char* storage_ = nullptr; | |
@@ -306,13 +308,6 @@ class StreamBase : public StreamResource { | |||
| 306 | 308 | Environment* env_; | |
| 307 | 309 | EmitToJSStreamListener default_listener_; | |
| 308 | 310 | ||
| 309 | - // These are called by the respective {Write,Shutdown}Wrap class. | ||
| 310 | - void AfterShutdown(ShutdownWrap* req, int status); | ||
| 311 | - void AfterWrite(WriteWrap* req, int status); | ||
| 312 | - | ||
| 313 | - template <typename Wrap, typename EmitEvent> | ||
| 314 | - void AfterRequest(Wrap* req_wrap, EmitEvent emit); | ||
| 315 | - | ||
| 316 | 311 | friend class WriteWrap; | |
| 317 | 312 | friend class ShutdownWrap; | |
| 318 | 313 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -220,6 +220,8 @@ void TLSWrap::SSLInfoCallback(const SSL* ssl_, int where, int ret) { | |||
| 220 | 220 | SSL* ssl = const_cast<SSL*>(ssl_); | |
| 221 | 221 | TLSWrap* c = static_cast<TLSWrap*>(SSL_get_app_data(ssl)); | |
| 222 | 222 | Environment* env = c->env(); | |
| 223 | + HandleScope handle_scope(env->isolate()); | ||
| 224 | + Context::Scope context_scope(env->context()); | ||
| 223 | 225 | Local<Object> object = c->object(); | |
| 224 | 226 | ||
| 225 | 227 | if (where & SSL_CB_HANDSHAKE_START) { | |
@@ -289,6 +291,8 @@ void TLSWrap::EncOut() { | |||
| 289 | 291 | NODE_COUNT_NET_BYTES_SENT(write_size_); | |
| 290 | 292 | ||
| 291 | 293 | if (!res.async) { | |
| 294 | + HandleScope handle_scope(env()->isolate()); | ||
| 295 | + | ||
| 292 | 296 | // Simulate asynchronous finishing, TLS cannot handle this at the moment. | |
| 293 | 297 | env()->SetImmediate([](Environment* env, void* data) { | |
| 294 | 298 | static_cast<TLSWrap*>(data)->OnStreamAfterWrite(nullptr, 0); | |
@@ -427,6 +431,7 @@ void TLSWrap::ClearOut() { | |||
| 427 | 431 | // shutdown cleanly (SSL_ERROR_ZERO_RETURN) even when read == 0. | |
| 428 | 432 | // See node#1642 and SSL_read(3SSL) for details. | |
| 429 | 433 | if (read <= 0) { | |
| 434 | + HandleScope handle_scope(env()->isolate()); | ||
| 430 | 435 | int err; | |
| 431 | 436 | Local<Value> arg = GetSSLError(read, &err, nullptr); | |
| 432 | 437 | ||
@@ -477,6 +482,9 @@ bool TLSWrap::ClearIn() { | |||
| 477 | 482 | } | |
| 478 | 483 | ||
| 479 | 484 | // Error or partial write | |
| 485 | + HandleScope handle_scope(env()->isolate()); | ||
| 486 | + Context::Scope context_scope(env()->context()); | ||
| 487 | + | ||
| 480 | 488 | int err; | |
| 481 | 489 | std::string error_str; | |
| 482 | 490 | Local<Value> arg = GetSSLError(written, &err, &error_str); | |
@@ -814,6 +822,9 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) { | |||
| 814 | 822 | if (servername == nullptr) | |
| 815 | 823 | return SSL_TLSEXT_ERR_OK; | |
| 816 | 824 | ||
| 825 | + HandleScope handle_scope(env->isolate()); | ||
| 826 | + Context::Scope context_scope(env->context()); | ||
| 827 | + | ||
| 817 | 828 | // Call the SNI callback and use its return value as context | |
| 818 | 829 | Local<Object> object = p->object(); | |
| 819 | 830 | Local<Value> ctx = object->Get(env->sni_context_string()); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments