@@ -47,42 +47,42 @@ export const arrayInstrumentations: Record<string | symbol, Function> = <any>{
47
47
fn : ( item : unknown , index : number , array : unknown [ ] ) => unknown ,
48
48
thisArg ?: unknown ,
49
49
) {
50
- return apply ( this , 'every' , fn , thisArg )
50
+ return apply ( this , 'every' , fn , thisArg , undefined , arguments )
51
51
} ,
52
52
53
53
filter (
54
54
fn : ( item : unknown , index : number , array : unknown [ ] ) => unknown ,
55
55
thisArg ?: unknown ,
56
56
) {
57
- return apply ( this , 'filter' , fn , thisArg , v => v . map ( toReactive ) )
57
+ return apply ( this , 'filter' , fn , thisArg , v => v . map ( toReactive ) , arguments )
58
58
} ,
59
59
60
60
find (
61
61
fn : ( item : unknown , index : number , array : unknown [ ] ) => boolean ,
62
62
thisArg ?: unknown ,
63
63
) {
64
- return apply ( this , 'find' , fn , thisArg , toReactive )
64
+ return apply ( this , 'find' , fn , thisArg , toReactive , arguments )
65
65
} ,
66
66
67
67
findIndex (
68
68
fn : ( item : unknown , index : number , array : unknown [ ] ) => boolean ,
69
69
thisArg ?: unknown ,
70
70
) {
71
- return apply ( this , 'findIndex' , fn , thisArg )
71
+ return apply ( this , 'findIndex' , fn , thisArg , undefined , arguments )
72
72
} ,
73
73
74
74
findLast (
75
75
fn : ( item : unknown , index : number , array : unknown [ ] ) => boolean ,
76
76
thisArg ?: unknown ,
77
77
) {
78
- return apply ( this , 'findLast' , fn , thisArg , toReactive )
78
+ return apply ( this , 'findLast' , fn , thisArg , toReactive , arguments )
79
79
} ,
80
80
81
81
findLastIndex (
82
82
fn : ( item : unknown , index : number , array : unknown [ ] ) => boolean ,
83
83
thisArg ?: unknown ,
84
84
) {
85
- return apply ( this , 'findLastIndex' , fn , thisArg )
85
+ return apply ( this , 'findLastIndex' , fn , thisArg , undefined , arguments )
86
86
} ,
87
87
88
88
// flat, flatMap could benefit from ARRAY_ITERATE but are not straight-forward to implement
@@ -91,7 +91,7 @@ export const arrayInstrumentations: Record<string | symbol, Function> = <any>{
91
91
fn : ( item : unknown , index : number , array : unknown [ ] ) => unknown ,
92
92
thisArg ?: unknown ,
93
93
) {
94
- return apply ( this , 'forEach' , fn , thisArg )
94
+ return apply ( this , 'forEach' , fn , thisArg , undefined , arguments )
95
95
} ,
96
96
97
97
includes ( ...args : unknown [ ] ) {
@@ -116,7 +116,7 @@ export const arrayInstrumentations: Record<string | symbol, Function> = <any>{
116
116
fn : ( item : unknown , index : number , array : unknown [ ] ) => unknown ,
117
117
thisArg ?: unknown ,
118
118
) {
119
- return apply ( this , 'map' , fn , thisArg )
119
+ return apply ( this , 'map' , fn , thisArg , undefined , arguments )
120
120
} ,
121
121
122
122
pop ( ) {
@@ -161,7 +161,7 @@ export const arrayInstrumentations: Record<string | symbol, Function> = <any>{
161
161
fn : ( item : unknown , index : number , array : unknown [ ] ) => unknown ,
162
162
thisArg ?: unknown ,
163
163
) {
164
- return apply ( this , 'some' , fn , thisArg )
164
+ return apply ( this , 'some' , fn , thisArg , undefined , arguments )
165
165
} ,
166
166
167
167
splice ( ...args : unknown [ ] ) {
@@ -227,6 +227,7 @@ function iterator(
227
227
// higher than that
228
228
type ArrayMethods = keyof Array < any > | 'findLast' | 'findLastIndex'
229
229
230
+ const arrayProto = Array . prototype
230
231
// instrument functions that read (potentially) all items
231
232
// to take ARRAY_ITERATE dependency
232
233
function apply (
@@ -235,8 +236,15 @@ function apply(
235
236
fn : ( item : unknown , index : number , array : unknown [ ] ) => unknown ,
236
237
thisArg ?: unknown ,
237
238
wrappedRetFn ?: ( result : any ) => unknown ,
239
+ args ?: IArguments ,
238
240
) {
239
241
const arr = shallowReadArray ( self )
242
+ let methodFn
243
+ // @ts -expect-error our code is limited to es2016 but user code is not
244
+ if ( ( methodFn = arr [ method ] ) !== arrayProto [ method ] ) {
245
+ return methodFn . apply ( arr , args )
246
+ }
247
+
240
248
let needsWrap = false
241
249
let wrappedFn = fn
242
250
if ( arr !== self ) {
@@ -251,8 +259,7 @@ function apply(
251
259
}
252
260
}
253
261
}
254
- // @ts -expect-error our code is limited to es2016 but user code is not
255
- const result = arr [ method ] ( wrappedFn , thisArg )
262
+ const result = methodFn . call ( arr , wrappedFn , thisArg )
256
263
return needsWrap && wrappedRetFn ? wrappedRetFn ( result ) : result
257
264
}
258
265
0 commit comments