node/test/addons/async-hooks-id/test.js
Attila Szegedi ffb9bfb206
src: add ExecutionAsyncId getter for any Context
Adds a variant of AsyncHooksGetExecutionAsyncId that takes a V8 Context
and returns the async ID belonging to the Environment (if any) of that
Context. Sometimes we want to use Isolate::GetEnteredOrMicrotaskContext
insteads of Isolate::GetCurrentContext (e.g. recording the async ID in
a V8 GC prologue callback) when current context is not set.

PR-URL: https://github.com/nodejs/node/pull/57820
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
2025-04-17 18:00:05 +00:00

35 lines
823 B
JavaScript

'use strict';
const common = require('../../common');
const assert = require('assert');
const binding = require(`./build/${common.buildType}/binding`);
const async_hooks = require('async_hooks');
assert.strictEqual(
binding.getExecutionAsyncId(),
async_hooks.executionAsyncId(),
);
assert.strictEqual(
binding.getExecutionAsyncIdWithContext(),
async_hooks.executionAsyncId(),
);
assert.strictEqual(
binding.getTriggerAsyncId(),
async_hooks.triggerAsyncId(),
);
process.nextTick(common.mustCall(() => {
assert.strictEqual(
binding.getExecutionAsyncId(),
async_hooks.executionAsyncId(),
);
assert.strictEqual(
binding.getExecutionAsyncIdWithContext(),
async_hooks.executionAsyncId(),
);
assert.strictEqual(
binding.getTriggerAsyncId(),
async_hooks.triggerAsyncId(),
);
}));