Skip to content

Commit

Permalink
async_wrap: add constructor for PromiseWrap
Browse files Browse the repository at this point in the history
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 <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
trevnorris authored and MylesBorins committed Sep 28, 2017
1 parent 6d9977f commit 154521a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
21 changes: 18 additions & 3 deletions src/async-wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void AsyncWrap::EmitAfter(Environment* env, double async_id) {
class PromiseWrap : public AsyncWrap {
public:
PromiseWrap(Environment* env, Local<Object> object, bool silent)
: AsyncWrap(env, object, PROVIDER_PROMISE, silent) {
: AsyncWrap(env, object, silent) {
MakeWeak(this);
}
size_t self_size() const override { return sizeof(*this); }
Expand Down Expand Up @@ -573,8 +573,7 @@ void LoadAsyncWrapperInfo(Environment* env) {

AsyncWrap::AsyncWrap(Environment* env,
Local<Object> object,
ProviderType provider,
bool silent)
ProviderType provider)
: BaseObject(env, object),
provider_type_(provider) {
CHECK_NE(provider, PROVIDER_NONE);
Expand All @@ -583,6 +582,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> 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);
}
Expand Down
7 changes: 5 additions & 2 deletions src/async-wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ class AsyncWrap : public BaseObject {

AsyncWrap(Environment* env,
v8::Local<v8::Object> object,
ProviderType provider,
bool silent = false);
ProviderType provider);

virtual ~AsyncWrap();

Expand Down Expand Up @@ -151,6 +150,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<v8::Object> promise, bool silent);
inline AsyncWrap();
const ProviderType provider_type_;
// Because the values may be Reset(), cannot be made const.
Expand Down

0 comments on commit 154521a

Please sign in to comment.