diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-02-24 17:42:27 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-03-15 12:53:06 +0100 |
commit | 8695273948846b999f528ede97c764638fbb6c40 (patch) | |
tree | 5f167a62c91f05d897cac2a9e77bc7d69746d30f /src/tls_wrap.cc | |
parent | 3ad7c1ae9778fd9a61b4e99eeab4291827700d55 (diff) | |
download | node-new-8695273948846b999f528ede97c764638fbb6c40.tar.gz |
src: tighten handle scopes for stream operations
Put `HandleScope`s and `Context::Scope`s where they are used,
and don’t create one for native stream callbacks automatically.
This is slightly less convenient but means that stream listeners
that don’t actually call back into JS don’t have to pay the
(small) cost of setting these up.
PR-URL: https://github.com/nodejs/node/pull/18936
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'src/tls_wrap.cc')
-rw-r--r-- | src/tls_wrap.cc | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 1cc5478bb5..cddef66c44 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -220,6 +220,8 @@ void TLSWrap::SSLInfoCallback(const SSL* ssl_, int where, int ret) { SSL* ssl = const_cast<SSL*>(ssl_); TLSWrap* c = static_cast<TLSWrap*>(SSL_get_app_data(ssl)); Environment* env = c->env(); + HandleScope handle_scope(env->isolate()); + Context::Scope context_scope(env->context()); Local<Object> object = c->object(); if (where & SSL_CB_HANDSHAKE_START) { @@ -289,6 +291,8 @@ void TLSWrap::EncOut() { NODE_COUNT_NET_BYTES_SENT(write_size_); if (!res.async) { + HandleScope handle_scope(env()->isolate()); + // Simulate asynchronous finishing, TLS cannot handle this at the moment. env()->SetImmediate([](Environment* env, void* data) { static_cast<TLSWrap*>(data)->OnStreamAfterWrite(nullptr, 0); @@ -427,6 +431,7 @@ void TLSWrap::ClearOut() { // shutdown cleanly (SSL_ERROR_ZERO_RETURN) even when read == 0. // See node#1642 and SSL_read(3SSL) for details. if (read <= 0) { + HandleScope handle_scope(env()->isolate()); int err; Local<Value> arg = GetSSLError(read, &err, nullptr); @@ -477,6 +482,9 @@ bool TLSWrap::ClearIn() { } // Error or partial write + HandleScope handle_scope(env()->isolate()); + Context::Scope context_scope(env()->context()); + int err; std::string error_str; Local<Value> arg = GetSSLError(written, &err, &error_str); @@ -814,6 +822,9 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) { if (servername == nullptr) return SSL_TLSEXT_ERR_OK; + HandleScope handle_scope(env->isolate()); + Context::Scope context_scope(env->context()); + // Call the SNI callback and use its return value as context Local<Object> object = p->object(); Local<Value> ctx = object->Get(env->sni_context_string()); |