summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Bevenius <daniel.bevenius@gmail.com>2018-03-15 07:38:19 +0100
committerDaniel Bevenius <daniel.bevenius@gmail.com>2018-03-18 11:56:45 +0100
commit75ff301ae093e337d637af8d02971cd680d7d0eb (patch)
treeb8d05ddc6fa47bbc46a5ed0d029f4440a1030af2 /src
parent1329844a0808705091891175a6bee58358380af6 (diff)
downloadandroid-node-v8-75ff301ae093e337d637af8d02971cd680d7d0eb.tar.gz
android-node-v8-75ff301ae093e337d637af8d02971cd680d7d0eb.tar.bz2
android-node-v8-75ff301ae093e337d637af8d02971cd680d7d0eb.zip
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: https://github.com/nodejs/node/pull/19366 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src')
-rw-r--r--src/async_wrap.cc23
-rw-r--r--src/async_wrap.h7
2 files changed, 12 insertions, 18 deletions
diff --git a/src/async_wrap.cc b/src/async_wrap.cc
index 404873c4d2..90b532d73b 100644
--- a/src/async_wrap.cc
+++ b/src/async_wrap.cc
@@ -228,7 +228,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, silent) {
+ : AsyncWrap(env, object, PROVIDER_PROMISE, -1, silent) {
MakeWeak(this);
}
size_t self_size() const override { return sizeof(*this); }
@@ -582,32 +582,23 @@ AsyncWrap::AsyncWrap(Environment* env,
Local<Object> object,
ProviderType provider,
double execution_async_id)
- : BaseObject(env, object),
- provider_type_(provider) {
- CHECK_NE(provider, PROVIDER_NONE);
- CHECK_GE(object->InternalFieldCount(), 1);
+ : AsyncWrap(env, object, provider, execution_async_id, false) {}
- // Shift provider value over to prevent id collision.
- persistent().SetWrapperClassId(NODE_ASYNC_ID_OFFSET + provider);
-
- // Use AsyncReset() call to execute the init() callbacks.
- AsyncReset(execution_async_id);
-}
-
-
-// This is specifically used by the PromiseWrap constructor.
AsyncWrap::AsyncWrap(Environment* env,
Local<Object> object,
+ ProviderType provider,
+ double execution_async_id,
bool silent)
: BaseObject(env, object),
- provider_type_(PROVIDER_PROMISE) {
+ provider_type_(provider) {
+ CHECK_NE(provider, PROVIDER_NONE);
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(-1, silent);
+ AsyncReset(execution_async_id, silent);
}
diff --git a/src/async_wrap.h b/src/async_wrap.h
index f0689d32f3..baaebb2a8b 100644
--- a/src/async_wrap.h
+++ b/src/async_wrap.h
@@ -185,8 +185,11 @@ class AsyncWrap : public BaseObject {
private:
friend class PromiseWrap;
- // This is specifically used by the PromiseWrap constructor.
- AsyncWrap(Environment* env, v8::Local<v8::Object> promise, bool silent);
+ AsyncWrap(Environment* env,
+ v8::Local<v8::Object> promise,
+ ProviderType provider,
+ double execution_async_id,
+ bool silent);
inline AsyncWrap();
const ProviderType provider_type_;
// Because the values may be Reset(), cannot be made const.