mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
async_hooks: expose async_wrap providers
docs: add asyncWrapProviders api doc tests(async_hooks): use internalBinding for comparisson fix(test-async-wrap): lint error docs: use REPLACEME for asyncWrapProviders update: use freeze and copy for asyncWrapProviders update(async_hooks): use primordials on asyncWrapProviders fix: use common to expect error docs(asyncWrapProviders): rephrase return type fix: lint md fix: lint md docs(async_hooks): typo Co-authored-by: Stephen Belanger <admin@stephenbelanger.com> update(asyncWrapProviders): add __proto__ as null Co-authored-by: Simone Busoli <simone.busoli@gmail.com> Co-authored-by: Michaël Zasso <targos@protonmail.com> test: adjust __proto__ assertion docs: add DEP0111 link PR-URL: https://github.com/nodejs/node/pull/40760 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
This commit is contained in:
parent
8ee9e1a1aa
commit
d10085bcb1
4 changed files with 37 additions and 0 deletions
|
@ -758,6 +758,18 @@ const server = net.createServer((conn) => {
|
|||
Promise contexts may not get valid `triggerAsyncId`s by default. See
|
||||
the section on [promise execution tracking][].
|
||||
|
||||
### `async_hooks.asyncWrapProviders`
|
||||
|
||||
<!-- YAML
|
||||
added: REPLACEME
|
||||
-->
|
||||
|
||||
* Returns: A map of provider types to the corresponding numeric id.
|
||||
This map contains all the event types that might be emitted by the `async_hooks.init()` event.
|
||||
|
||||
This feature suppresses the deprecated usage of `process.binding('async_wrap').Providers`.
|
||||
See: [DEP0111][]
|
||||
|
||||
## Promise execution tracking
|
||||
|
||||
By default, promise executions are not assigned `asyncId`s due to the relatively
|
||||
|
@ -841,6 +853,7 @@ The documentation for this class has moved [`AsyncResource`][].
|
|||
|
||||
The documentation for this class has moved [`AsyncLocalStorage`][].
|
||||
|
||||
[DEP0111]: deprecations.md#dep0111-processbinding
|
||||
[Hook Callbacks]: #hook-callbacks
|
||||
[PromiseHooks]: https://docs.google.com/document/d/1rda3yKGHimKIhg5YeoAmCOtyURgsbTH_qaYR79FELlk/edit
|
||||
[`AsyncLocalStorage`]: async_context.md#class-asynclocalstorage
|
||||
|
|
|
@ -11,6 +11,7 @@ const {
|
|||
ObjectIs,
|
||||
ReflectApply,
|
||||
Symbol,
|
||||
ObjectFreeze,
|
||||
} = primordials;
|
||||
|
||||
const {
|
||||
|
@ -29,6 +30,7 @@ const internal_async_hooks = require('internal/async_hooks');
|
|||
// resource gets gced.
|
||||
const { registerDestroyHook } = internal_async_hooks;
|
||||
const {
|
||||
asyncWrap,
|
||||
executionAsyncId,
|
||||
triggerAsyncId,
|
||||
// Private API
|
||||
|
@ -352,6 +354,7 @@ module.exports = {
|
|||
executionAsyncId,
|
||||
triggerAsyncId,
|
||||
executionAsyncResource,
|
||||
asyncWrapProviders: ObjectFreeze({ __proto__: null, ...asyncWrap.Providers }),
|
||||
// Embedder API
|
||||
AsyncResource,
|
||||
};
|
||||
|
|
|
@ -612,5 +612,8 @@ module.exports = {
|
|||
after: emitAfterNative,
|
||||
destroy: emitDestroyNative,
|
||||
promise_resolve: emitPromiseResolveNative
|
||||
},
|
||||
asyncWrap: {
|
||||
Providers: async_wrap.Providers,
|
||||
}
|
||||
};
|
||||
|
|
18
test/async-hooks/test-async-wrap-providers.js
Normal file
18
test/async-hooks/test-async-wrap-providers.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Flags: --expose-internals
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const { internalBinding } = require('internal/test/binding');
|
||||
const providers = internalBinding('async_wrap').Providers;
|
||||
const assert = require('assert');
|
||||
const { asyncWrapProviders } = require('async_hooks');
|
||||
|
||||
assert.ok(typeof asyncWrapProviders === 'object');
|
||||
assert.deepStrictEqual(asyncWrapProviders, { __proto__: null, ...providers });
|
||||
|
||||
const providerKeys = Object.keys(asyncWrapProviders);
|
||||
assert.throws(() => {
|
||||
asyncWrapProviders[providerKeys[0]] = 'another value';
|
||||
}, common.expectsError({
|
||||
name: 'TypeError',
|
||||
}), 'should not allow modify asyncWrap providers');
|
Loading…
Add table
Add a link
Reference in a new issue