diff options
author | Daniel Bevenius <daniel.bevenius@gmail.com> | 2018-03-16 16:33:55 +0300 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2018-03-20 09:42:00 +0300 |
commit | 5a4a1cba2445d71aadf4ebf4350090dfdb32d871 (patch) | |
tree | 1e10b7b287b2f5c884350521b72e3379c9b61b48 /lib/internal/async_hooks.js | |
parent | 489b916c7d14032df46fea332133f38a1cadb40d (diff) |
async_hooks: add copyHooks function
This commit introduces a copyHooks function that can be used by
storeActiveHooks and restoreActiveHooks to remove some code duplication.
PR-URL: https://github.com/nodejs/node/pull/19391
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Diffstat (limited to 'lib/internal/async_hooks.js')
-rw-r--r-- | lib/internal/async_hooks.js | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index 5a2a8153f3f..90155fa3c77 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -213,11 +213,15 @@ function storeActiveHooks() { // Don't want to make the assumption that kInit to kDestroy are indexes 0 to // 4. So do this the long way. active_hooks.tmp_fields = []; - active_hooks.tmp_fields[kInit] = async_hook_fields[kInit]; - active_hooks.tmp_fields[kBefore] = async_hook_fields[kBefore]; - active_hooks.tmp_fields[kAfter] = async_hook_fields[kAfter]; - active_hooks.tmp_fields[kDestroy] = async_hook_fields[kDestroy]; - active_hooks.tmp_fields[kPromiseResolve] = async_hook_fields[kPromiseResolve]; + copyHooks(active_hooks.tmp_fields, async_hook_fields); +} + +function copyHooks(destination, source) { + destination[kInit] = source[kInit]; + destination[kBefore] = source[kBefore]; + destination[kAfter] = source[kAfter]; + destination[kDestroy] = source[kDestroy]; + destination[kPromiseResolve] = source[kPromiseResolve]; } @@ -225,11 +229,7 @@ function storeActiveHooks() { // during hook callback execution. function restoreActiveHooks() { active_hooks.array = active_hooks.tmp_array; - async_hook_fields[kInit] = active_hooks.tmp_fields[kInit]; - async_hook_fields[kBefore] = active_hooks.tmp_fields[kBefore]; - async_hook_fields[kAfter] = active_hooks.tmp_fields[kAfter]; - async_hook_fields[kDestroy] = active_hooks.tmp_fields[kDestroy]; - async_hook_fields[kPromiseResolve] = active_hooks.tmp_fields[kPromiseResolve]; + copyHooks(async_hook_fields, active_hooks.tmp_fields); active_hooks.tmp_array = null; active_hooks.tmp_fields = null; |