From a7b7c92990b9eb2bd1d5a6f465fc2baa49589410 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Wed, 14 Jun 2017 01:04:04 -0600 Subject: [PATCH] async_wrap: add constructor for PromiseWrap Another optional argument is about to be added to AsyncWrap. So instead of piling them on, create a separate constructor specifically for PromiseWrap since it's the only class that uses the "silent" argument. PR-URL: https://github.com/nodejs/node/pull/14208 Reviewed-By: James M Snell Reviewed-By: Refael Ackermann --- src/async-wrap.cc | 21 ++++++++++++++++++--- src/async-wrap.h | 7 +++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/async-wrap.cc b/src/async-wrap.cc index 404c51c6af..beb04343e0 100644 --- a/src/async-wrap.cc +++ b/src/async-wrap.cc @@ -246,7 +246,7 @@ void AsyncWrap::EmitAfter(Environment* env, double async_id) { class PromiseWrap : public AsyncWrap { public: PromiseWrap(Environment* env, Local object, bool silent) - : AsyncWrap(env, object, PROVIDER_PROMISE, silent) { + : AsyncWrap(env, object, silent) { MakeWeak(this); } size_t self_size() const override { return sizeof(*this); } @@ -574,8 +574,7 @@ void LoadAsyncWrapperInfo(Environment* env) { AsyncWrap::AsyncWrap(Environment* env, Local object, - ProviderType provider, - bool silent) + ProviderType provider) : BaseObject(env, object), provider_type_(provider) { CHECK_NE(provider, PROVIDER_NONE); @@ -584,6 +583,22 @@ AsyncWrap::AsyncWrap(Environment* env, // Shift provider value over to prevent id collision. persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider); + // Use AsyncReset() call to execute the init() callbacks. + AsyncReset(); +} + + +// This is specifically used by the PromiseWrap constructor. +AsyncWrap::AsyncWrap(Environment* env, + Local object, + bool silent) + : BaseObject(env, object), + provider_type_(PROVIDER_PROMISE) { + CHECK_GE(object->InternalFieldCount(), 1); + + // Shift provider value over to prevent id collision. + persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider_type_); + // Use AsyncReset() call to execute the init() callbacks. AsyncReset(silent); } diff --git a/src/async-wrap.h b/src/async-wrap.h index dd9d038582..386c39537a 100644 --- a/src/async-wrap.h +++ b/src/async-wrap.h @@ -94,8 +94,7 @@ class AsyncWrap : public BaseObject { AsyncWrap(Environment* env, v8::Local object, - ProviderType provider, - bool silent = false); + ProviderType provider); virtual ~AsyncWrap(); @@ -148,6 +147,10 @@ class AsyncWrap : public BaseObject { virtual size_t self_size() const = 0; private: + friend class PromiseWrap; + + // This is specifically used by the PromiseWrap constructor. + AsyncWrap(Environment* env, v8::Local promise, bool silent); inline AsyncWrap(); const ProviderType provider_type_; // Because the values may be Reset(), cannot be made const.