Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Belanger <admin@stephenbelanger.com>2020-06-06 22:06:06 +0300
committerAnna Henningsen <anna@addaleax.net>2020-06-19 18:37:25 +0300
commit59e6230a30954f78836048b581d8db61582242ef (patch)
tree861f4260ba22fb1807380cf39d2a8ea14f9b15ac /lib/internal/async_hooks.js
parent2c4864762d2b97a55ef15fe44b7691d67de51766 (diff)
async_hooks: callback trampoline for MakeCallback
PR-URL: https://github.com/nodejs/node/pull/33801 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Diffstat (limited to 'lib/internal/async_hooks.js')
-rw-r--r--lib/internal/async_hooks.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js
index da7b2745e53..e400f24689f 100644
--- a/lib/internal/async_hooks.js
+++ b/lib/internal/async_hooks.js
@@ -1,15 +1,18 @@
'use strict';
const {
+ ArrayPrototypeUnshift,
Error,
FunctionPrototypeBind,
ObjectPrototypeHasOwnProperty,
ObjectDefineProperty,
Promise,
+ ReflectApply,
Symbol,
} = primordials;
const async_wrap = internalBinding('async_wrap');
+const { setCallbackTrampoline } = async_wrap;
/* async_hook_fields is a Uint32Array wrapping the uint32_t array of
* Environment::AsyncHooks::fields_[]. Each index tracks the number of active
* hooks for each type.
@@ -103,6 +106,26 @@ const emitDestroyNative = emitHookFactory(destroy_symbol, 'emitDestroyNative');
const emitPromiseResolveNative =
emitHookFactory(promise_resolve_symbol, 'emitPromiseResolveNative');
+function callbackTrampoline(asyncId, cb, domain_cb, ...args) {
+ if (hasHooks(kBefore))
+ emitBeforeNative(asyncId);
+
+ let result;
+ if (typeof domain_cb === 'function') {
+ ArrayPrototypeUnshift(args, cb);
+ result = ReflectApply(domain_cb, this, args);
+ } else {
+ result = ReflectApply(cb, this, args);
+ }
+
+ if (hasHooks(kAfter))
+ emitAfterNative(asyncId);
+
+ return result;
+}
+
+setCallbackTrampoline(callbackTrampoline);
+
const topLevelResource = {};
function executionAsyncResource() {