From e3fd7520d0671f639fc59e0470cb0909166480c3 Mon Sep 17 00:00:00 2001 From: Anna Henningsen <anna@addaleax.net> Date: Wed, 30 Jan 2019 18:42:25 +0100 Subject: [PATCH] src: pass along errors from tls object creation PR-URL: https://github.com/nodejs/node/pull/25822 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> --- src/tls_wrap.cc | 15 ++++++++++----- src/tls_wrap.h | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 7349c5c68da710..3f39e7a91ce611 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -48,13 +48,11 @@ using v8::String; using v8::Value; TLSWrap::TLSWrap(Environment* env, + Local<Object> obj, Kind kind, StreamBase* stream, SecureContext* sc) - : AsyncWrap(env, - env->tls_wrap_constructor_function() - ->NewInstance(env->context()).ToLocalChecked(), - AsyncWrap::PROVIDER_TLSWRAP), + : AsyncWrap(env, obj, AsyncWrap::PROVIDER_TLSWRAP), SSLWrap<TLSWrap>(env, sc, kind), StreamBase(env), sc_(sc) { @@ -159,7 +157,14 @@ void TLSWrap::Wrap(const FunctionCallbackInfo<Value>& args) { StreamBase* stream = static_cast<StreamBase*>(stream_obj->Value()); CHECK_NOT_NULL(stream); - TLSWrap* res = new TLSWrap(env, kind, stream, Unwrap<SecureContext>(sc)); + Local<Object> obj; + if (!env->tls_wrap_constructor_function() + ->NewInstance(env->context()) + .ToLocal(&obj)) { + return; + } + + TLSWrap* res = new TLSWrap(env, obj, kind, stream, Unwrap<SecureContext>(sc)); args.GetReturnValue().Set(res->object()); } diff --git a/src/tls_wrap.h b/src/tls_wrap.h index d3cbb992bafb29..be694526abf203 100644 --- a/src/tls_wrap.h +++ b/src/tls_wrap.h @@ -108,6 +108,7 @@ class TLSWrap : public AsyncWrap, static const int kSimultaneousBufferCount = 10; TLSWrap(Environment* env, + v8::Local<v8::Object> obj, Kind kind, StreamBase* stream, crypto::SecureContext* sc);