async_hooks: improve property descriptors in als.bind

The length property should be non enumerable to match behavior of
normal functions.

The asyncResource property is enumerable and therefore it should be
also writable to avoid issues like there:
https://github.com/nodejs/node/pull/30932#discussion_r379679982

Both properties should be configurable.

Refs: https://github.com/nodejs/node/pull/34574

PR-URL: https://github.com/nodejs/node/pull/34620
Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Gerhard Stoebich 2020-08-04 10:15:42 +02:00
parent 0bb70b0a02
commit 3ea94ec845
1 changed files with 5 additions and 1 deletions

View File

@ -220,12 +220,16 @@ class AsyncResource {
const ret = this.runInAsyncScope.bind(this, fn);
ObjectDefineProperties(ret, {
'length': {
enumerable: true,
configurable: true,
enumerable: false,
value: fn.length,
writable: false,
},
'asyncResource': {
configurable: true,
enumerable: true,
value: this,
writable: true,
}
});
return ret;