From 1850879b0e6d5e1e52e35790ab448c4c6dee34f0 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Thu, 8 Oct 2015 10:57:12 -0600 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/3282 Reviewed-By: Fedor Indutny --- src/js_stream.cc | 5 ++++- test/parallel/test-js-stream-call-properties.js | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-js-stream-call-properties.js diff --git a/src/js_stream.cc b/src/js_stream.cc index 77595ad..25938f1 100644 --- a/src/js_stream.cc +++ b/src/js_stream.cc @@ -44,7 +44,10 @@ AsyncWrap* JSStream::GetAsyncWrap() { bool JSStream::IsAlive() { - return MakeCallback(env()->isalive_string(), 0, nullptr)->IsTrue(); + v8::Local fn = object()->Get(env()->isalive_string()); + if (!fn->IsFunction()) + return false; + return MakeCallback(fn.As(), 0, nullptr)->IsTrue(); } diff --git a/test/parallel/test-js-stream-call-properties.js b/test/parallel/test-js-stream-call-properties.js new file mode 100644 index 0000000..c6b1adb --- /dev/null +++ b/test/parallel/test-js-stream-call-properties.js @@ -0,0 +1,8 @@ +'use strict'; + +const common = require('../common'); +const util = require('util'); +const JSStream = process.binding('js_stream').JSStream; + +// Testing if will abort when properties are printed. +util.inspect(new JSStream()); -- 2.7.4