Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit9fafb0a

Browse files
authored
async_hooks: deprecate the AsyncResource.bind asyncResource property
Runtime-deprecates the `asyncResource` property that is attached tothe wrapper function returned by `asyncResource.bind()`. This propertyis not expected to align with the equivalent `asyncContext.wrap()`API in the proposed TC39 standard.PR-URL:#46432Reviewed-By: Chengzhong Wu <legendecas@gmail.com>Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>Reviewed-By: Michaël Zasso <targos@protonmail.com>Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent1118db7 commit9fafb0a

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

‎doc/api/async_context.md

Lines changed: 10 additions & 6 deletions
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

Lines changed: 14 additions & 0 deletions
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

Lines changed: 11 additions & 3 deletions
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+
letself=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+
returnself;
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
returnbound;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp