summaryrefslogtreecommitdiff
path: root/src/stream_base-inl.h
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/stream_base-inl.h
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/stream_base-inl.h')
-rw-r--r--src/stream_base-inl.h42
1 files changed, 16 insertions, 26 deletions
diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h
index 1534dcd1d5..c87393e6fc 100644
--- a/src/stream_base-inl.h
+++ b/src/stream_base-inl.h
@@ -106,22 +106,33 @@ inline void StreamResource::RemoveStreamListener(StreamListener* listener) {
listener->previous_listener_ = nullptr;
}
-
inline uv_buf_t StreamResource::EmitAlloc(size_t suggested_size) {
+#ifdef DEBUG
+ v8::SealHandleScope handle_scope(v8::Isolate::GetCurrent());
+#endif
return listener_->OnStreamAlloc(suggested_size);
}
inline void StreamResource::EmitRead(ssize_t nread, const uv_buf_t& buf) {
+#ifdef DEBUG
+ v8::SealHandleScope handle_scope(v8::Isolate::GetCurrent());
+#endif
if (nread > 0)
bytes_read_ += static_cast<uint64_t>(nread);
listener_->OnStreamRead(nread, buf);
}
inline void StreamResource::EmitAfterWrite(WriteWrap* w, int status) {
+#ifdef DEBUG
+ v8::SealHandleScope handle_scope(v8::Isolate::GetCurrent());
+#endif
listener_->OnStreamAfterWrite(w, status);
}
inline void StreamResource::EmitAfterShutdown(ShutdownWrap* w, int status) {
+#ifdef DEBUG
+ v8::SealHandleScope handle_scope(v8::Isolate::GetCurrent());
+#endif
listener_->OnStreamAfterShutdown(w, status);
}
@@ -133,29 +144,6 @@ inline Environment* StreamBase::stream_env() const {
return env_;
}
-inline void StreamBase::AfterWrite(WriteWrap* req_wrap, int status) {
- AfterRequest(req_wrap, [&]() {
- EmitAfterWrite(req_wrap, status);
- });
-}
-
-inline void StreamBase::AfterShutdown(ShutdownWrap* req_wrap, int status) {
- AfterRequest(req_wrap, [&]() {
- EmitAfterShutdown(req_wrap, status);
- });
-}
-
-template<typename Wrap, typename EmitEvent>
-inline void StreamBase::AfterRequest(Wrap* req_wrap, EmitEvent emit) {
- Environment* env = stream_env();
-
- v8::HandleScope handle_scope(env->isolate());
- v8::Context::Scope context_scope(env->context());
-
- emit();
- req_wrap->Dispose();
-}
-
inline int StreamBase::Shutdown(v8::Local<v8::Object> req_wrap_obj) {
Environment* env = stream_env();
if (req_wrap_obj.IsEmpty()) {
@@ -387,7 +375,8 @@ void StreamBase::JSMethod(const FunctionCallbackInfo<Value>& args) {
inline void ShutdownWrap::OnDone(int status) {
- stream()->AfterShutdown(this, status);
+ stream()->EmitAfterShutdown(this, status);
+ Dispose();
}
inline void WriteWrap::SetAllocatedStorage(char* data, size_t size) {
@@ -405,7 +394,8 @@ inline size_t WriteWrap::StorageSize() const {
}
inline void WriteWrap::OnDone(int status) {
- stream()->AfterWrite(this, status);
+ stream()->EmitAfterWrite(this, status);
+ Dispose();
}
inline void StreamReq::Done(int status, const char* error_str) {