diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 4871cd405d1ec0..df6bb9c56fd2ee 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -49,13 +49,11 @@ using v8::String; using v8::Value; TLSWrap::TLSWrap(Environment* env, + Local 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(env, sc, kind), StreamBase(env), sc_(sc) { @@ -160,7 +158,14 @@ void TLSWrap::Wrap(const FunctionCallbackInfo& args) { StreamBase* stream = static_cast(stream_obj->Value()); CHECK_NOT_NULL(stream); - TLSWrap* res = new TLSWrap(env, kind, stream, Unwrap(sc)); + Local obj; + if (!env->tls_wrap_constructor_function() + ->NewInstance(env->context()) + .ToLocal(&obj)) { + return; + } + + TLSWrap* res = new TLSWrap(env, obj, kind, stream, Unwrap(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 obj, Kind kind, StreamBase* stream, crypto::SecureContext* sc);