Browse Source

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 <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
canary-base
Trevor Norris 8 years ago
parent
commit
e1eae3cf9f
No known key found for this signature in database GPG Key ID: 251CA676820DC7F3
  1. 21
      src/async-wrap.cc
  2. 7
      src/async-wrap.h

21
src/async-wrap.cc

@ -243,7 +243,7 @@ void AsyncWrap::EmitAfter(Environment* env, double async_id) {
class PromiseWrap : public AsyncWrap { class PromiseWrap : public AsyncWrap {
public: public:
PromiseWrap(Environment* env, Local<Object> object, bool silent) PromiseWrap(Environment* env, Local<Object> object, bool silent)
: AsyncWrap(env, object, PROVIDER_PROMISE, silent) { : AsyncWrap(env, object, silent) {
MakeWeak(this); MakeWeak(this);
} }
size_t self_size() const override { return sizeof(*this); } size_t self_size() const override { return sizeof(*this); }
@ -573,8 +573,7 @@ void LoadAsyncWrapperInfo(Environment* env) {
AsyncWrap::AsyncWrap(Environment* env, AsyncWrap::AsyncWrap(Environment* env,
Local<Object> object, Local<Object> object,
ProviderType provider, ProviderType provider)
bool silent)
: BaseObject(env, object), : BaseObject(env, object),
provider_type_(provider) { provider_type_(provider) {
CHECK_NE(provider, PROVIDER_NONE); CHECK_NE(provider, PROVIDER_NONE);
@ -583,6 +582,22 @@ AsyncWrap::AsyncWrap(Environment* env,
// Shift provider value over to prevent id collision. // Shift provider value over to prevent id collision.
persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider); 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. // Use AsyncReset() call to execute the init() callbacks.
AsyncReset(silent); AsyncReset(silent);
} }

7
src/async-wrap.h

@ -94,8 +94,7 @@ class AsyncWrap : public BaseObject {
AsyncWrap(Environment* env, AsyncWrap(Environment* env,
v8::Local<v8::Object> object, v8::Local<v8::Object> object,
ProviderType provider, ProviderType provider);
bool silent = false);
virtual ~AsyncWrap(); virtual ~AsyncWrap();
@ -150,6 +149,10 @@ class AsyncWrap : public BaseObject {
virtual size_t self_size() const = 0; virtual size_t self_size() const = 0;
private: private:
friend class PromiseWrap;
// This is specifically used by the PromiseWrap constructor.
AsyncWrap(Environment* env, v8::Local<v8::Object> promise, bool silent);
inline AsyncWrap(); inline AsyncWrap();
const ProviderType provider_type_; const ProviderType provider_type_;
// Because the values may be Reset(), cannot be made const. // Because the values may be Reset(), cannot be made const.

Loading…
Cancel
Save