Skip to content

Commit 9fafb0a

Browse files
authoredFeb 3, 2023
async_hooks: deprecate the AsyncResource.bind asyncResource property
Runtime-deprecates the `asyncResource` property that is attached to the wrapper function returned by `asyncResource.bind()`. This property is not expected to align with the equivalent `asyncContext.wrap()` API in the proposed TC39 standard. PR-URL: #46432 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 1118db7 commit 9fafb0a

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed
 

‎doc/api/async_context.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,11 @@ added:
455455
- v14.8.0
456456
- v12.19.0
457457
changes:
458+
- version: REPLACEME
459+
pr-url: https://github.com/nodejs/node/pull/46432
460+
description: The `asyncResource` property added to the bound function
461+
has been deprecated and will be removed in a future
462+
version.
458463
- version:
459464
- v17.8.0
460465
- v16.15.0
@@ -473,16 +478,18 @@ changes:
473478

474479
Binds the given function to the current execution context.
475480

476-
The returned function will have an `asyncResource` property referencing
477-
the `AsyncResource` to which the function is bound.
478-
479481
### `asyncResource.bind(fn[, thisArg])`
480482

481483
<!-- YAML
482484
added:
483485
- v14.8.0
484486
- v12.19.0
485487
changes:
488+
- version: REPLACEME
489+
pr-url: https://github.com/nodejs/node/pull/46432
490+
description: The `asyncResource` property added to the bound function
491+
has been deprecated and will be removed in a future
492+
version.
486493
- version:
487494
- v17.8.0
488495
- v16.15.0
@@ -499,9 +506,6 @@ changes:
499506

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

502-
The returned function will have an `asyncResource` property referencing
503-
the `AsyncResource` to which the function is bound.
504-
505509
### `asyncResource.runInAsyncScope(fn[, thisArg, ...args])`
506510

507511
<!-- YAML

‎doc/api/deprecations.md

+14
Original file line numberDiff line numberDiff line change
@@ -3339,6 +3339,20 @@ In a future version of Node.js, [`message.headers`][],
33393339
[`message.headersDistinct`][], [`message.trailers`][], and
33403340
[`message.trailersDistinct`][] will be read-only.
33413341

3342+
### DEP0172: The `asyncResource` property of `AsyncResource` bound functions
3343+
3344+
<!-- YAML
3345+
changes:
3346+
- version: REPLACEME
3347+
pr-url: https://github.com/nodejs/node/pull/46432
3348+
description: Runtime-deprecation.
3349+
-->
3350+
3351+
Type: Runtime
3352+
3353+
In a future version of Node.js, the `asyncResource` property will no longer
3354+
be added when a function is bound to an `AsyncResource`.
3355+
33423356
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
33433357
[RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3
33443358
[RFC 8247 Section 2.4]: https://www.rfc-editor.org/rfc/rfc8247#section-2.4

‎lib/async_hooks.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ const {
2020
ERR_ASYNC_TYPE,
2121
ERR_INVALID_ASYNC_ID
2222
} = require('internal/errors').codes;
23-
const { kEmptyObject } = require('internal/util');
23+
const {
24+
deprecate,
25+
kEmptyObject,
26+
} = require('internal/util');
2427
const {
2528
validateFunction,
2629
validateString,
@@ -237,6 +240,7 @@ class AsyncResource {
237240
} else {
238241
bound = FunctionPrototypeBind(this.runInAsyncScope, this, fn, thisArg);
239242
}
243+
let self = this;
240244
ObjectDefineProperties(bound, {
241245
'length': {
242246
__proto__: null,
@@ -249,8 +253,12 @@ class AsyncResource {
249253
__proto__: null,
250254
configurable: true,
251255
enumerable: true,
252-
value: this,
253-
writable: true,
256+
get: deprecate(function() {
257+
return self;
258+
}, 'The asyncResource property on bound functions is deprecated', 'DEP0172'),
259+
set: deprecate(function(val) {
260+
self = val;
261+
}, 'The asyncResource property on bound functions is deprecated', 'DEP0172'),
254262
}
255263
});
256264
return bound;

0 commit comments

Comments
 (0)
Please sign in to comment.