1
1
'use strict' ;
2
2
3
3
const {
4
+ ArrayPrototypeIncludes,
5
+ ArrayPrototypeIndexOf,
6
+ ArrayPrototypePush,
7
+ ArrayPrototypeSplice,
8
+ FunctionPrototypeBind,
4
9
NumberIsSafeInteger,
5
10
ObjectDefineProperties,
6
11
ObjectIs,
@@ -85,7 +90,7 @@ class AsyncHook {
85
90
const [ hooks_array , hook_fields ] = getHookArrays ( ) ;
86
91
87
92
// Each hook is only allowed to be added once.
88
- if ( hooks_array . includes ( this ) )
93
+ if ( ArrayPrototypeIncludes ( hooks_array , this ) )
89
94
return this ;
90
95
91
96
const prev_kTotals = hook_fields [ kTotals ] ;
@@ -99,7 +104,7 @@ class AsyncHook {
99
104
hook_fields [ kTotals ] += hook_fields [ kDestroy ] += + ! ! this [ destroy_symbol ] ;
100
105
hook_fields [ kTotals ] +=
101
106
hook_fields [ kPromiseResolve ] += + ! ! this [ promise_resolve_symbol ] ;
102
- hooks_array . push ( this ) ;
107
+ ArrayPrototypePush ( hooks_array , this ) ;
103
108
104
109
if ( prev_kTotals === 0 && hook_fields [ kTotals ] > 0 ) {
105
110
enableHooks ( ) ;
@@ -113,7 +118,7 @@ class AsyncHook {
113
118
disable ( ) {
114
119
const [ hooks_array , hook_fields ] = getHookArrays ( ) ;
115
120
116
- const index = hooks_array . indexOf ( this ) ;
121
+ const index = ArrayPrototypeIndexOf ( hooks_array , this ) ;
117
122
if ( index === - 1 )
118
123
return this ;
119
124
@@ -125,7 +130,7 @@ class AsyncHook {
125
130
hook_fields [ kTotals ] += hook_fields [ kDestroy ] -= + ! ! this [ destroy_symbol ] ;
126
131
hook_fields [ kTotals ] +=
127
132
hook_fields [ kPromiseResolve ] -= + ! ! this [ promise_resolve_symbol ] ;
128
- hooks_array . splice ( index , 1 ) ;
133
+ ArrayPrototypeSplice ( hooks_array , index , 1 ) ;
129
134
130
135
if ( prev_kTotals > 0 && hook_fields [ kTotals ] === 0 ) {
131
136
disableHooks ( ) ;
@@ -218,7 +223,7 @@ class AsyncResource {
218
223
bind ( fn ) {
219
224
if ( typeof fn !== 'function' )
220
225
throw new ERR_INVALID_ARG_TYPE ( 'fn' , 'Function' , fn ) ;
221
- const ret = this . runInAsyncScope . bind ( this , fn ) ;
226
+ const ret = FunctionPrototypeBind ( this . runInAsyncScope , this , fn ) ;
222
227
ObjectDefineProperties ( ret , {
223
228
'length' : {
224
229
configurable : true ,
@@ -264,7 +269,8 @@ class AsyncLocalStorage {
264
269
if ( this . enabled ) {
265
270
this . enabled = false ;
266
271
// If this.enabled, the instance must be in storageList
267
- storageList . splice ( storageList . indexOf ( this ) , 1 ) ;
272
+ ArrayPrototypeSplice ( storageList ,
273
+ ArrayPrototypeIndexOf ( storageList , this ) , 1 ) ;
268
274
if ( storageList . length === 0 ) {
269
275
storageHook . disable ( ) ;
270
276
}
@@ -274,7 +280,7 @@ class AsyncLocalStorage {
274
280
_enable ( ) {
275
281
if ( ! this . enabled ) {
276
282
this . enabled = true ;
277
- storageList . push ( this ) ;
283
+ ArrayPrototypePush ( storageList , this ) ;
278
284
storageHook . enable ( ) ;
279
285
}
280
286
}
0 commit comments