mirror of
https://github.com/nodejs/node.git
synced 2025-05-09 17:22:44 +00:00

- Merge the two almost-but-not-quite identical `MakeCallback()` implementations - Provide a public `CallbackScope` class for embedders in order to enable `MakeCallback()`-like behaviour without tying that to calling a JS function PR-URL: https://github.com/nodejs/node/pull/14697 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
23 lines
542 B
JavaScript
23 lines
542 B
JavaScript
'use strict';
|
|
|
|
const common = require('../../common');
|
|
const assert = require('assert');
|
|
const async_hooks = require('async_hooks');
|
|
const { runInCallbackScope } = require(`./build/${common.buildType}/binding`);
|
|
|
|
let insideHook = false;
|
|
async_hooks.createHook({
|
|
before: common.mustCall((id) => {
|
|
assert.strictEqual(id, 1000);
|
|
insideHook = true;
|
|
}),
|
|
after: common.mustCall((id) => {
|
|
assert.strictEqual(id, 1000);
|
|
insideHook = false;
|
|
})
|
|
}).enable();
|
|
|
|
runInCallbackScope({}, 1000, 1000, () => {
|
|
assert(insideHook);
|
|
});
|