Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async_hooks: deprecate the AsyncResource.bind asyncResource property #46432

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions doc/api/async_context.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ added:
- v14.8.0
- v12.19.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/46432
description: The `asyncResource` property added to the bound function
has been deprecated and will be removed in a future
version.
- version:
- v17.8.0
- v16.15.0
Expand All @@ -484,16 +489,18 @@ changes:

Binds the given function to the current execution context.

The returned function will have an `asyncResource` property referencing
the `AsyncResource` to which the function is bound.

### `asyncResource.bind(fn[, thisArg])`

<!-- YAML
added:
- v14.8.0
- v12.19.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/46432
description: The `asyncResource` property added to the bound function
has been deprecated and will be removed in a future
version.
- version:
- v17.8.0
- v16.15.0
Expand All @@ -510,9 +517,6 @@ changes:

Binds the given function to execute to this `AsyncResource`'s scope.

The returned function will have an `asyncResource` property referencing
the `AsyncResource` to which the function is bound.

### `asyncResource.runInAsyncScope(fn[, thisArg, ...args])`

<!-- YAML
Expand Down
14 changes: 14 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -3339,6 +3339,20 @@ In a future version of Node.js, [`message.headers`][],
[`message.headersDistinct`][], [`message.trailers`][], and
[`message.trailersDistinct`][] will be read-only.

### DEP0172: The `asyncResource` property of `AsyncResource` bound functions

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/46432
description: Runtime-deprecation.
-->

Type: Runtime

In a future version of Node.js, the `asyncResource` property will no longer
be added when a function is bound to an `AsyncResource`.

[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
[RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3
[RFC 8247 Section 2.4]: https://www.rfc-editor.org/rfc/rfc8247#section-2.4
Expand Down
14 changes: 11 additions & 3 deletions lib/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const {
ERR_ASYNC_TYPE,
ERR_INVALID_ASYNC_ID
} = require('internal/errors').codes;
const { kEmptyObject } = require('internal/util');
const {
deprecate,
kEmptyObject,
} = require('internal/util');
const {
validateFunction,
validateObject,
Expand Down Expand Up @@ -238,6 +241,7 @@ class AsyncResource {
} else {
bound = FunctionPrototypeBind(this.runInAsyncScope, this, fn, thisArg);
}
let self = this;
ObjectDefineProperties(bound, {
'length': {
__proto__: null,
Expand All @@ -250,8 +254,12 @@ class AsyncResource {
__proto__: null,
configurable: true,
enumerable: true,
value: this,
writable: true,
get: deprecate(function() {
return self;
}, 'The asyncResource property on bound functions is deprecated', 'DEP0172'),
set: deprecate(function(val) {
self = val;
}, 'The asyncResource property on bound functions is deprecated', 'DEP0172'),
jasnell marked this conversation as resolved.
Show resolved Hide resolved
}
});
return bound;
Expand Down