Skip to content

Commit 1850879

Browse files
committed
js_stream: prevent abort if isalive doesn't exist
Attempting to check IsAlive() on a JSStream before the isAlive() callback can be set in JS causes a CHECK to fail in MakeCallback. Instead return false if the callback hasn't been set. PR-URL: #3282 Reviewed-By: Fedor Indutny <[email protected]>
1 parent 26a7ec6 commit 1850879

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/js_stream.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ AsyncWrap* JSStream::GetAsyncWrap() {
4444

4545

4646
bool JSStream::IsAlive() {
47-
return MakeCallback(env()->isalive_string(), 0, nullptr)->IsTrue();
47+
v8::Local<v8::Value> fn = object()->Get(env()->isalive_string());
48+
if (!fn->IsFunction())
49+
return false;
50+
return MakeCallback(fn.As<v8::Function>(), 0, nullptr)->IsTrue();
4851
}
4952

5053

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const util = require('util');
5+
const JSStream = process.binding('js_stream').JSStream;
6+
7+
// Testing if will abort when properties are printed.
8+
util.inspect(new JSStream());

0 commit comments

Comments
 (0)