Skip to content

Commit 5b2f650

Browse files
danbevcodebytere
authored andcommitted
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 b407060 commit 5b2f650

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

src/async_wrap.cc

+7-16
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ void AsyncWrap::EmitAfter(Environment* env, double async_id) {
254254
class PromiseWrap : public AsyncWrap {
255255
public:
256256
PromiseWrap(Environment* env, Local<Object> object, bool silent)
257-
: AsyncWrap(env, object, silent) {
257+
: AsyncWrap(env, object, PROVIDER_PROMISE, -1, silent) {
258258
MakeWeak(this);
259259
}
260260
size_t self_size() const override { return sizeof(*this); }
@@ -626,32 +626,23 @@ AsyncWrap::AsyncWrap(Environment* env,
626626
Local<Object> object,
627627
ProviderType provider,
628628
double execution_async_id)
629-
: BaseObject(env, object),
630-
provider_type_(provider) {
631-
CHECK_NE(provider, PROVIDER_NONE);
632-
CHECK_GE(object->InternalFieldCount(), 1);
629+
: AsyncWrap(env, object, provider, execution_async_id, false) {}
633630

634-
// Shift provider value over to prevent id collision.
635-
persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider);
636-
637-
// Use AsyncReset() call to execute the init() callbacks.
638-
AsyncReset(execution_async_id);
639-
}
640-
641-
642-
// This is specifically used by the PromiseWrap constructor.
643631
AsyncWrap::AsyncWrap(Environment* env,
644632
Local<Object> object,
633+
ProviderType provider,
634+
double execution_async_id,
645635
bool silent)
646636
: BaseObject(env, object),
647-
provider_type_(PROVIDER_PROMISE) {
637+
provider_type_(provider) {
638+
CHECK_NE(provider, PROVIDER_NONE);
648639
CHECK_GE(object->InternalFieldCount(), 1);
649640

650641
// Shift provider value over to prevent id collision.
651642
persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider_type_);
652643

653644
// Use AsyncReset() call to execute the init() callbacks.
654-
AsyncReset(-1, silent);
645+
AsyncReset(execution_async_id, silent);
655646
}
656647

657648

src/async_wrap.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,11 @@ class AsyncWrap : public BaseObject {
173173
private:
174174
friend class PromiseWrap;
175175

176-
// This is specifically used by the PromiseWrap constructor.
177-
AsyncWrap(Environment* env, v8::Local<v8::Object> promise, bool silent);
176+
AsyncWrap(Environment* env,
177+
v8::Local<v8::Object> promise,
178+
ProviderType provider,
179+
double execution_async_id,
180+
bool silent);
178181
inline AsyncWrap();
179182
const ProviderType provider_type_;
180183
// Because the values may be Reset(), cannot be made const.

0 commit comments

Comments
 (0)