Skip to content

Commit 75ff301

Browse files
committed
src: make AsyncWrap constructors delegate
Currently, there is an AsyncWrap constructor that is only used by PromiseWrap. This constructor has a body which is very similar to the other AsyncWrap constructor. This commit suggests updating the private constructor that is used by PromiseWrap and also have the second constructor delegate to this one to avoid the code duplication. PR-URL: #19366 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 1329844 commit 75ff301

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

src/async_wrap.cc

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void AsyncWrap::EmitAfter(Environment* env, double async_id) {
228228
class PromiseWrap : public AsyncWrap {
229229
public:
230230
PromiseWrap(Environment* env, Local<Object> object, bool silent)
231-
: AsyncWrap(env, object, silent) {
231+
: AsyncWrap(env, object, PROVIDER_PROMISE, -1, silent) {
232232
MakeWeak(this);
233233
}
234234
size_t self_size() const override { return sizeof(*this); }
@@ -582,32 +582,23 @@ AsyncWrap::AsyncWrap(Environment* env,
582582
Local<Object> object,
583583
ProviderType provider,
584584
double execution_async_id)
585-
: BaseObject(env, object),
586-
provider_type_(provider) {
587-
CHECK_NE(provider, PROVIDER_NONE);
588-
CHECK_GE(object->InternalFieldCount(), 1);
585+
: AsyncWrap(env, object, provider, execution_async_id, false) {}
589586

590-
// Shift provider value over to prevent id collision.
591-
persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider);
592-
593-
// Use AsyncReset() call to execute the init() callbacks.
594-
AsyncReset(execution_async_id);
595-
}
596-
597-
598-
// This is specifically used by the PromiseWrap constructor.
599587
AsyncWrap::AsyncWrap(Environment* env,
600588
Local<Object> object,
589+
ProviderType provider,
590+
double execution_async_id,
601591
bool silent)
602592
: BaseObject(env, object),
603-
provider_type_(PROVIDER_PROMISE) {
593+
provider_type_(provider) {
594+
CHECK_NE(provider, PROVIDER_NONE);
604595
CHECK_GE(object->InternalFieldCount(), 1);
605596

606597
// Shift provider value over to prevent id collision.
607598
persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider_type_);
608599

609600
// Use AsyncReset() call to execute the init() callbacks.
610-
AsyncReset(-1, silent);
601+
AsyncReset(execution_async_id, silent);
611602
}
612603

613604

src/async_wrap.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,11 @@ class AsyncWrap : public BaseObject {
185185
private:
186186
friend class PromiseWrap;
187187

188-
// This is specifically used by the PromiseWrap constructor.
189-
AsyncWrap(Environment* env, v8::Local<v8::Object> promise, bool silent);
188+
AsyncWrap(Environment* env,
189+
v8::Local<v8::Object> promise,
190+
ProviderType provider,
191+
double execution_async_id,
192+
bool silent);
190193
inline AsyncWrap();
191194
const ProviderType provider_type_;
192195
// Because the values may be Reset(), cannot be made const.

0 commit comments

Comments
 (0)