@@ -47,42 +47,42 @@ export const arrayInstrumentations: Record<string | symbol, Function> = <any>{
4747 fn : ( item : unknown , index : number , array : unknown [ ] ) => unknown ,
4848 thisArg ?: unknown ,
4949 ) {
50- return apply ( this , 'every' , fn , thisArg )
50+ return apply ( this , 'every' , fn , thisArg , undefined , arguments )
5151 } ,
5252
5353 filter (
5454 fn : ( item : unknown , index : number , array : unknown [ ] ) => unknown ,
5555 thisArg ?: unknown ,
5656 ) {
57- return apply ( this , 'filter' , fn , thisArg , v => v . map ( toReactive ) )
57+ return apply ( this , 'filter' , fn , thisArg , v => v . map ( toReactive ) , arguments )
5858 } ,
5959
6060 find (
6161 fn : ( item : unknown , index : number , array : unknown [ ] ) => boolean ,
6262 thisArg ?: unknown ,
6363 ) {
64- return apply ( this , 'find' , fn , thisArg , toReactive )
64+ return apply ( this , 'find' , fn , thisArg , toReactive , arguments )
6565 } ,
6666
6767 findIndex (
6868 fn : ( item : unknown , index : number , array : unknown [ ] ) => boolean ,
6969 thisArg ?: unknown ,
7070 ) {
71- return apply ( this , 'findIndex' , fn , thisArg )
71+ return apply ( this , 'findIndex' , fn , thisArg , undefined , arguments )
7272 } ,
7373
7474 findLast (
7575 fn : ( item : unknown , index : number , array : unknown [ ] ) => boolean ,
7676 thisArg ?: unknown ,
7777 ) {
78- return apply ( this , 'findLast' , fn , thisArg , toReactive )
78+ return apply ( this , 'findLast' , fn , thisArg , toReactive , arguments )
7979 } ,
8080
8181 findLastIndex (
8282 fn : ( item : unknown , index : number , array : unknown [ ] ) => boolean ,
8383 thisArg ?: unknown ,
8484 ) {
85- return apply ( this , 'findLastIndex' , fn , thisArg )
85+ return apply ( this , 'findLastIndex' , fn , thisArg , undefined , arguments )
8686 } ,
8787
8888 // 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>{
9191 fn : ( item : unknown , index : number , array : unknown [ ] ) => unknown ,
9292 thisArg ?: unknown ,
9393 ) {
94- return apply ( this , 'forEach' , fn , thisArg )
94+ return apply ( this , 'forEach' , fn , thisArg , undefined , arguments )
9595 } ,
9696
9797 includes ( ...args : unknown [ ] ) {
@@ -116,7 +116,7 @@ export const arrayInstrumentations: Record<string | symbol, Function> = <any>{
116116 fn : ( item : unknown , index : number , array : unknown [ ] ) => unknown ,
117117 thisArg ?: unknown ,
118118 ) {
119- return apply ( this , 'map' , fn , thisArg )
119+ return apply ( this , 'map' , fn , thisArg , undefined , arguments )
120120 } ,
121121
122122 pop ( ) {
@@ -161,7 +161,7 @@ export const arrayInstrumentations: Record<string | symbol, Function> = <any>{
161161 fn : ( item : unknown , index : number , array : unknown [ ] ) => unknown ,
162162 thisArg ?: unknown ,
163163 ) {
164- return apply ( this , 'some' , fn , thisArg )
164+ return apply ( this , 'some' , fn , thisArg , undefined , arguments )
165165 } ,
166166
167167 splice ( ...args : unknown [ ] ) {
@@ -227,6 +227,7 @@ function iterator(
227227// higher than that
228228type ArrayMethods = keyof Array < any > | 'findLast' | 'findLastIndex'
229229
230+ const arrayProto = Array . prototype
230231// instrument functions that read (potentially) all items
231232// to take ARRAY_ITERATE dependency
232233function apply (
@@ -235,8 +236,15 @@ function apply(
235236 fn : ( item : unknown , index : number , array : unknown [ ] ) => unknown ,
236237 thisArg ?: unknown ,
237238 wrappedRetFn ?: ( result : any ) => unknown ,
239+ args ?: IArguments ,
238240) {
239241 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+
240248 let needsWrap = false
241249 let wrappedFn = fn
242250 if ( arr !== self ) {
@@ -251,8 +259,7 @@ function apply(
251259 }
252260 }
253261 }
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 )
256263 return needsWrap && wrappedRetFn ? wrappedRetFn ( result ) : result
257264}
258265
0 commit comments