Skip to content

Commit 09b3fae

Browse files
trevnorrisMylesBorins
authored andcommitted
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: #14208 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent bbdd93f commit 09b3fae

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/async-wrap.cc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ void AsyncWrap::EmitAfter(Environment* env, double async_id) {
243243
class PromiseWrap : public AsyncWrap {
244244
public:
245245
PromiseWrap(Environment* env, Local<Object> object, bool silent)
246-
: AsyncWrap(env, object, PROVIDER_PROMISE, silent) {
246+
: AsyncWrap(env, object, silent) {
247247
MakeWeak(this);
248248
}
249249
size_t self_size() const override { return sizeof(*this); }
@@ -573,8 +573,7 @@ void LoadAsyncWrapperInfo(Environment* env) {
573573

574574
AsyncWrap::AsyncWrap(Environment* env,
575575
Local<Object> object,
576-
ProviderType provider,
577-
bool silent)
576+
ProviderType provider)
578577
: BaseObject(env, object),
579578
provider_type_(provider) {
580579
CHECK_NE(provider, PROVIDER_NONE);
@@ -583,6 +582,22 @@ AsyncWrap::AsyncWrap(Environment* env,
583582
// Shift provider value over to prevent id collision.
584583
persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider);
585584

585+
// Use AsyncReset() call to execute the init() callbacks.
586+
AsyncReset();
587+
}
588+
589+
590+
// This is specifically used by the PromiseWrap constructor.
591+
AsyncWrap::AsyncWrap(Environment* env,
592+
Local<Object> object,
593+
bool silent)
594+
: BaseObject(env, object),
595+
provider_type_(PROVIDER_PROMISE) {
596+
CHECK_GE(object->InternalFieldCount(), 1);
597+
598+
// Shift provider value over to prevent id collision.
599+
persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider_type_);
600+
586601
// Use AsyncReset() call to execute the init() callbacks.
587602
AsyncReset(silent);
588603
}

src/async-wrap.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ class AsyncWrap : public BaseObject {
9595

9696
AsyncWrap(Environment* env,
9797
v8::Local<v8::Object> object,
98-
ProviderType provider,
99-
bool silent = false);
98+
ProviderType provider);
10099

101100
virtual ~AsyncWrap();
102101

@@ -151,6 +150,10 @@ class AsyncWrap : public BaseObject {
151150
virtual size_t self_size() const = 0;
152151

153152
private:
153+
friend class PromiseWrap;
154+
155+
// This is specifically used by the PromiseWrap constructor.
156+
AsyncWrap(Environment* env, v8::Local<v8::Object> promise, bool silent);
154157
inline AsyncWrap();
155158
const ProviderType provider_type_;
156159
// Because the values may be Reset(), cannot be made const.

0 commit comments

Comments
 (0)