diff --git a/src/js_stream.cc b/src/js_stream.cc index af10fcac399851..68f6915eb6c56e 100644 --- a/src/js_stream.cc +++ b/src/js_stream.cc @@ -20,6 +20,7 @@ using v8::Int32; using v8::Isolate; using v8::Local; using v8::Object; +using v8::TryCatch; using v8::Value; @@ -169,6 +170,8 @@ void JSStream::ReadBuffer(const FunctionCallbackInfo& args) { const char* data = buffer.data(); int len = buffer.length(); + TryCatch try_catch(args.GetIsolate()); + // Repeatedly ask the stream's owner for memory, copy the data that we // just read from JS into those buffers and emit them as reads. while (len != 0) { @@ -182,6 +185,10 @@ void JSStream::ReadBuffer(const FunctionCallbackInfo& args) { len -= static_cast(avail); wrap->EmitRead(avail, buf); } + + if (try_catch.HasCaught()) { + try_catch.ReThrow(); + } } diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 0f94ea501cea64..e1ac63c881abef 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -462,6 +462,7 @@ bool ContextifyContext::IsStillInitializing(const ContextifyContext* ctx) { void ContextifyContext::PropertyGetterCallback( Local property, const PropertyCallbackInfo& args) { + Environment* env = Environment::GetCurrent(args); ContextifyContext* ctx = ContextifyContext::Get(args); // Still initializing @@ -469,6 +470,8 @@ void ContextifyContext::PropertyGetterCallback( Local context = ctx->context(); Local sandbox = ctx->sandbox(); + + TryCatchScope try_catch(env); MaybeLocal maybe_rv = sandbox->GetRealNamedProperty(context, property); if (maybe_rv.IsEmpty()) { @@ -478,6 +481,9 @@ void ContextifyContext::PropertyGetterCallback( Local rv; if (maybe_rv.ToLocal(&rv)) { + if (try_catch.HasCaught() && !try_catch.HasTerminated()) { + try_catch.ReThrow(); + } if (rv == sandbox) rv = ctx->global_proxy(); diff --git a/src/node_messaging.cc b/src/node_messaging.cc index 0195a1bb2e448c..1243002a94c165 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -916,6 +916,7 @@ Maybe MessagePort::PostMessage(Environment* env, const TransferList& transfer_v) { Isolate* isolate = env->isolate(); Local obj = object(isolate); + TryCatchScope try_catch(env); std::shared_ptr msg = std::make_shared(); @@ -924,6 +925,9 @@ Maybe MessagePort::PostMessage(Environment* env, Maybe serialization_maybe = msg->Serialize(env, context, message_v, transfer_v, obj); + if (try_catch.HasCaught() && !try_catch.HasTerminated()) { + try_catch.ReThrow(); + } if (data_ == nullptr) { return serialization_maybe; } diff --git a/test/addons/make-callback-recurse/binding.cc b/test/addons/make-callback-recurse/binding.cc index 3fe3212ee3c8f5..145247954a31c4 100644 --- a/test/addons/make-callback-recurse/binding.cc +++ b/test/addons/make-callback-recurse/binding.cc @@ -8,6 +8,7 @@ using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; using v8::Object; +using v8::TryCatch; using v8::Value; namespace { @@ -19,8 +20,12 @@ void MakeCallback(const FunctionCallbackInfo& args) { Local recv = args[0].As(); Local method = args[1].As(); + TryCatch try_catch(isolate); node::MakeCallback(isolate, recv, method, 0, nullptr, node::async_context{0, 0}); + if (try_catch.HasCaught()) { + try_catch.ReThrow(); + } } void Initialize(Local exports) {