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: https://github.com/nodejs/node/pull/16269
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Anna Henningsen 2017-10-17 23:36:18 +02:00
parent ba4a0a6f5f
commit 127f83ab8d
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9

View File

@ -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,18 +56,24 @@ 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();
}
@ -73,6 +81,7 @@ int JSStream::ReadStop() {
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;