File tree 2 files changed +18
-10
lines changed
2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -223,15 +223,18 @@ class AsyncResource {
223
223
return this [ trigger_async_id_symbol ] ;
224
224
}
225
225
226
- bind ( fn , thisArg = this ) {
226
+ bind ( fn , thisArg ) {
227
227
validateFunction ( fn , 'fn' ) ;
228
- const ret =
229
- FunctionPrototypeBind (
230
- this . runInAsyncScope ,
231
- this ,
232
- fn ,
233
- thisArg ) ;
234
- ObjectDefineProperties ( ret , {
228
+ const runInAsyncScope = FunctionPrototypeBind (
229
+ this . runInAsyncScope ,
230
+ this ,
231
+ fn ) ;
232
+ const bound = function ( ...args ) {
233
+ return runInAsyncScope (
234
+ thisArg !== undefined ? thisArg : this ,
235
+ ...args ) ;
236
+ } ;
237
+ ObjectDefineProperties ( bound , {
235
238
'length' : {
236
239
configurable : true ,
237
240
enumerable : false ,
@@ -245,7 +248,7 @@ class AsyncResource {
245
248
writable : true ,
246
249
}
247
250
} ) ;
248
- return ret ;
251
+ return bound ;
249
252
}
250
253
251
254
static bind ( fn , type , thisArg ) {
Original file line number Diff line number Diff line change @@ -41,11 +41,16 @@ const fn3 = asyncResource.bind(common.mustCall(function() {
41
41
fn3 ( ) ;
42
42
43
43
const fn4 = asyncResource . bind ( common . mustCall ( function ( ) {
44
- assert . strictEqual ( this , asyncResource ) ;
44
+ assert . strictEqual ( this , undefined ) ;
45
45
} ) ) ;
46
46
fn4 ( ) ;
47
47
48
48
const fn5 = asyncResource . bind ( common . mustCall ( function ( ) {
49
49
assert . strictEqual ( this , false ) ;
50
50
} ) , false ) ;
51
51
fn5 ( ) ;
52
+
53
+ const fn6 = asyncResource . bind ( common . mustCall ( function ( ) {
54
+ assert . strictEqual ( this , 'test' ) ;
55
+ } ) ) ;
56
+ fn6 . call ( 'test' ) ;
You can’t perform that action at this time.
0 commit comments