mirror of
https://github.com/nodejs/node.git
synced 2025-04-28 13:40:37 +00:00

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>
35 lines
823 B
JavaScript
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(),
|
|
);
|
|
}));
|