mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
lib: fix AsyncResource.bind not using 'this' from the caller by default
PR-URL: https://github.com/nodejs/node/pull/42177 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Bryan English <bryan@bryanenglish.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
2f2f422ff8
commit
409c594887
3 changed files with 28 additions and 10 deletions
|
@ -5,6 +5,7 @@ const {
|
|||
ArrayPrototypeIndexOf,
|
||||
ArrayPrototypePush,
|
||||
ArrayPrototypeSplice,
|
||||
ArrayPrototypeUnshift,
|
||||
FunctionPrototypeBind,
|
||||
NumberIsSafeInteger,
|
||||
ObjectDefineProperties,
|
||||
|
@ -223,15 +224,19 @@ class AsyncResource {
|
|||
return this[trigger_async_id_symbol];
|
||||
}
|
||||
|
||||
bind(fn, thisArg = this) {
|
||||
bind(fn, thisArg) {
|
||||
validateFunction(fn, 'fn');
|
||||
const ret =
|
||||
FunctionPrototypeBind(
|
||||
this.runInAsyncScope,
|
||||
this,
|
||||
fn,
|
||||
thisArg);
|
||||
ObjectDefineProperties(ret, {
|
||||
let bound;
|
||||
if (thisArg === undefined) {
|
||||
const resource = this;
|
||||
bound = function(...args) {
|
||||
ArrayPrototypeUnshift(args, fn, this);
|
||||
return ReflectApply(resource.runInAsyncScope, resource, args);
|
||||
};
|
||||
} else {
|
||||
bound = FunctionPrototypeBind(this.runInAsyncScope, this, fn, thisArg);
|
||||
}
|
||||
ObjectDefineProperties(bound, {
|
||||
'length': {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
|
@ -245,7 +250,7 @@ class AsyncResource {
|
|||
writable: true,
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
return bound;
|
||||
}
|
||||
|
||||
static bind(fn, type, thisArg) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue