summaryrefslogtreecommitdiff
path: root/src/node_http2.cc
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-02-24 17:42:27 +0100
committerAnna Henningsen <anna@addaleax.net>2018-03-15 12:53:06 +0100
commit8695273948846b999f528ede97c764638fbb6c40 (patch)
tree5f167a62c91f05d897cac2a9e77bc7d69746d30f /src/node_http2.cc
parent3ad7c1ae9778fd9a61b4e99eeab4291827700d55 (diff)
downloadandroid-node-v8-8695273948846b999f528ede97c764638fbb6c40.tar.gz
android-node-v8-8695273948846b999f528ede97c764638fbb6c40.tar.bz2
android-node-v8-8695273948846b999f528ede97c764638fbb6c40.zip
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/node_http2.cc')
-rw-r--r--src/node_http2.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/node_http2.cc b/src/node_http2.cc
index d683b075bc..939e0011bd 100644
--- a/src/node_http2.cc
+++ b/src/node_http2.cc
@@ -1132,6 +1132,8 @@ void Http2StreamListener::OnStreamRead(ssize_t nread, const uv_buf_t& buf) {
Http2Stream* stream = static_cast<Http2Stream*>(stream_);
Http2Session* session = stream->session();
Environment* env = stream->env();
+ HandleScope handle_scope(env->isolate());
+ Context::Scope context_scope(env->context());
if (nread < 0) {
PassReadErrorToPreviousListener(nread);
@@ -1422,6 +1424,7 @@ void Http2Session::OnStreamAfterWrite(WriteWrap* w, int status) {
void Http2Session::MaybeScheduleWrite() {
CHECK_EQ(flags_ & SESSION_STATE_WRITE_SCHEDULED, 0);
if (session_ != nullptr && nghttp2_session_want_write(session_)) {
+ HandleScope handle_scope(env()->isolate());
DEBUG_HTTP2SESSION(this, "scheduling write");
flags_ |= SESSION_STATE_WRITE_SCHEDULED;
env()->SetImmediate([](Environment* env, void* data) {
@@ -1632,6 +1635,8 @@ inline Http2Stream* Http2Session::SubmitRequest(
// Callback used to receive inbound data from the i/o stream
void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf) {
+ HandleScope handle_scope(env()->isolate());
+ Context::Scope context_scope(env()->context());
Http2Scope h2scope(this);
CHECK_NE(stream_, nullptr);
DEBUG_HTTP2SESSION2(this, "receiving %d bytes", nread);
@@ -1661,8 +1666,6 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf) {
CHECK_LE(static_cast<size_t>(nread), stream_buf_.len);
Isolate* isolate = env()->isolate();
- HandleScope scope(isolate);
- Context::Scope context_scope(env()->context());
// Create an array buffer for the read data. DATA frames will be emitted
// as slices of this array buffer to avoid having to copy memory.