Permalink
Browse files

src: allow top-level calls into JSStream

Allow `JSStream` instances to be used more flexibly by explicitly
enabling calls that have no JS stack below them.

PR-URL: #16269
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
addaleax authored and MylesBorins committed Oct 17, 2017
1 parent 73915d3 commit 2788cb75245ce9aa7247d97f698fecc8f5804188
Showing with 10 additions and 0 deletions.
  1. +10 −0 src/js_stream.cc
View
@@ -45,6 +45,8 @@ AsyncWrap* JSStream::GetAsyncWrap() {
bool JSStream::IsAlive() {
HandleScope scope(env()->isolate());
Context::Scope context_scope(env()->context());
v8::Local<v8::Value> fn = object()->Get(env()->isalive_string());
if (!fn->IsFunction())
return false;
@@ -54,25 +56,32 @@ bool JSStream::IsAlive() {
bool JSStream::IsClosing() {
HandleScope scope(env()->isolate());
Context::Scope context_scope(env()->context());
return MakeCallback(env()->isclosing_string(), 0, nullptr)
.ToLocalChecked()->IsTrue();
}
int JSStream::ReadStart() {
HandleScope scope(env()->isolate());
Context::Scope context_scope(env()->context());
return MakeCallback(env()->onreadstart_string(), 0, nullptr)
.ToLocalChecked()->Int32Value();
}
int JSStream::ReadStop() {
HandleScope scope(env()->isolate());
Context::Scope context_scope(env()->context());
return MakeCallback(env()->onreadstop_string(), 0, nullptr)
.ToLocalChecked()->Int32Value();
}
int JSStream::DoShutdown(ShutdownWrap* req_wrap) {
HandleScope scope(env()->isolate());
Context::Scope context_scope(env()->context());
Local<Value> argv[] = {
req_wrap->object()
@@ -93,6 +102,7 @@ int JSStream::DoWrite(WriteWrap* w,
CHECK_EQ(send_handle, nullptr);
HandleScope scope(env()->isolate());
Context::Scope context_scope(env()->context());
Local<Array> bufs_arr = Array::New(env()->isolate(), count);
Local<Object> buf;

0 comments on commit 2788cb7

Please sign in to comment.