diff --git a/lib/async_hooks.js b/lib/async_hooks.js index 0c425e694584eb..f32c9131850c78 100644 --- a/lib/async_hooks.js +++ b/lib/async_hooks.js @@ -74,12 +74,11 @@ class AsyncHook { return this; const prev_kTotals = hook_fields[kTotals]; - hook_fields[kTotals] = 0; // createHook() has already enforced that the callbacks are all functions, // so here simply increment the count of whether each callbacks exists or // not. - hook_fields[kTotals] += hook_fields[kInit] += +!!this[init_symbol]; + hook_fields[kTotals] = hook_fields[kInit] += +!!this[init_symbol]; hook_fields[kTotals] += hook_fields[kBefore] += +!!this[before_symbol]; hook_fields[kTotals] += hook_fields[kAfter] += +!!this[after_symbol]; hook_fields[kTotals] += hook_fields[kDestroy] += +!!this[destroy_symbol]; @@ -102,9 +101,8 @@ class AsyncHook { return this; const prev_kTotals = hook_fields[kTotals]; - hook_fields[kTotals] = 0; - hook_fields[kTotals] += hook_fields[kInit] -= +!!this[init_symbol]; + hook_fields[kTotals] = hook_fields[kInit] -= +!!this[init_symbol]; hook_fields[kTotals] += hook_fields[kBefore] -= +!!this[before_symbol]; hook_fields[kTotals] += hook_fields[kAfter] -= +!!this[after_symbol]; hook_fields[kTotals] += hook_fields[kDestroy] -= +!!this[destroy_symbol];