@@ -49,17 +49,16 @@ function createArrayInstrumentations() {
49
49
// instrument identity-sensitive Array methods to account for possible reactive
50
50
// values
51
51
; ( [ 'includes' , 'indexOf' , 'lastIndexOf' ] as const ) . forEach ( key => {
52
- const method = Array . prototype [ key ] as any
53
52
instrumentations [ key ] = function ( this : unknown [ ] , ...args : unknown [ ] ) {
54
- const arr = toRaw ( this )
53
+ const arr = toRaw ( this ) as any
55
54
for ( let i = 0 , l = this . length ; i < l ; i ++ ) {
56
55
track ( arr , TrackOpTypes . GET , i + '' )
57
56
}
58
57
// we run the method using the original args first (which may be reactive)
59
- const res = method . apply ( arr , args )
58
+ const res = arr [ key ] ( ... args )
60
59
if ( res === - 1 || res === false ) {
61
60
// if that didn't work, run it again using raw values.
62
- return method . apply ( arr , args . map ( toRaw ) )
61
+ return arr [ key ] ( ... args . map ( toRaw ) )
63
62
} else {
64
63
return res
65
64
}
@@ -68,10 +67,9 @@ function createArrayInstrumentations() {
68
67
// instrument length-altering mutation methods to avoid length being tracked
69
68
// which leads to infinite loops in some cases (#2137)
70
69
; ( [ 'push' , 'pop' , 'shift' , 'unshift' , 'splice' ] as const ) . forEach ( key => {
71
- const method = Array . prototype [ key ] as any
72
70
instrumentations [ key ] = function ( this : unknown [ ] , ...args : unknown [ ] ) {
73
71
pauseTracking ( )
74
- const res = method . apply ( this , args )
72
+ const res = ( toRaw ( this ) as any ) [ key ] . apply ( this , args )
75
73
resetTracking ( )
76
74
return res
77
75
}
0 commit comments