Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0691649

Browse filesBrowse files
RafaelGSStargos
authored andcommitted
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: #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>
1 parent 415b42f commit 0691649
Copy full SHA for 0691649

File tree

Expand file treeCollapse file tree

4 files changed

+37
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+37
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/async_hooks.md‎

Copy file name to clipboardExpand all lines: doc/api/async_hooks.md
+13Lines changed: 13 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,18 @@ const server = net.createServer((conn) => {
758758
Promise contexts may not get valid `triggerAsyncId`s by default. See
759759
the section on [promise execution tracking][].
760760
761+
### `async_hooks.asyncWrapProviders`
762+
763+
<!-- YAML
764+
added: REPLACEME
765+
-->
766+
767+
* Returns: A map of provider types to the corresponding numeric id.
768+
This map contains all the event types that might be emitted by the `async_hooks.init()` event.
769+
770+
This feature suppresses the deprecated usage of `process.binding('async_wrap').Providers`.
771+
See: [DEP0111][]
772+
761773
## Promise execution tracking
762774
763775
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`][].
841853
842854
The documentation for this class has moved [`AsyncLocalStorage`][].
843855
856+
[DEP0111]: deprecations.md#dep0111-processbinding
844857
[Hook Callbacks]: #hook-callbacks
845858
[PromiseHooks]: https://docs.google.com/document/d/1rda3yKGHimKIhg5YeoAmCOtyURgsbTH_qaYR79FELlk/edit
846859
[`AsyncLocalStorage`]: async_context.md#class-asynclocalstorage
Collapse file

‎lib/async_hooks.js‎

Copy file name to clipboardExpand all lines: lib/async_hooks.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111
ObjectIs,
1212
ReflectApply,
1313
Symbol,
14+
ObjectFreeze,
1415
} = primordials;
1516

1617
const {
@@ -29,6 +30,7 @@ const internal_async_hooks = require('internal/async_hooks');
2930
// resource gets gced.
3031
const { registerDestroyHook } = internal_async_hooks;
3132
const {
33+
asyncWrap,
3234
executionAsyncId,
3335
triggerAsyncId,
3436
// Private API
@@ -352,6 +354,7 @@ module.exports = {
352354
executionAsyncId,
353355
triggerAsyncId,
354356
executionAsyncResource,
357+
asyncWrapProviders: ObjectFreeze({ __proto__: null, ...asyncWrap.Providers }),
355358
// Embedder API
356359
AsyncResource,
357360
};
Collapse file

‎lib/internal/async_hooks.js‎

Copy file name to clipboardExpand all lines: lib/internal/async_hooks.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,5 +612,8 @@ module.exports = {
612612
after: emitAfterNative,
613613
destroy: emitDestroyNative,
614614
promise_resolve: emitPromiseResolveNative
615+
},
616+
asyncWrap: {
617+
Providers: async_wrap.Providers,
615618
}
616619
};
Collapse file
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
4+
const common = require('../common');
5+
const { internalBinding } = require('internal/test/binding');
6+
const providers = internalBinding('async_wrap').Providers;
7+
const assert = require('assert');
8+
const { asyncWrapProviders } = require('async_hooks');
9+
10+
assert.ok(typeof asyncWrapProviders === 'object');
11+
assert.deepStrictEqual(asyncWrapProviders, { __proto__: null, ...providers });
12+
13+
const providerKeys = Object.keys(asyncWrapProviders);
14+
assert.throws(() => {
15+
asyncWrapProviders[providerKeys[0]] = 'another value';
16+
}, common.expectsError({
17+
name: 'TypeError',
18+
}), 'should not allow modify asyncWrap providers');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.