( self: unknown[], method: ArrayMethods, fn: (item: unknown, index: number, array: unknown[]) => unknown, thisArg?: unknown, wrappedRetFn?: (result: any) => unknown, args?: IArguments, )
| 268 | // instrument functions that read (potentially) all items |
| 269 | // to take ARRAY_ITERATE dependency |
| 270 | function apply( |
| 271 | self: unknown[], |
| 272 | method: ArrayMethods, |
| 273 | fn: (item: unknown, index: number, array: unknown[]) => unknown, |
| 274 | thisArg?: unknown, |
| 275 | wrappedRetFn?: (result: any) => unknown, |
| 276 | args?: IArguments, |
| 277 | ) { |
| 278 | const arr = shallowReadArray(self) |
| 279 | const needsWrap = arr !== self && !isShallow(self) |
| 280 | // @ts-expect-error our code is limited to es2016 but user code is not |
| 281 | const methodFn = arr[method] |
| 282 | |
| 283 | // #11759 |
| 284 | // If the method being called is from a user-extended Array, the arguments will be unknown |
| 285 | // (unknown order and unknown parameter types). In this case, we skip the shallowReadArray |
| 286 | // handling and directly call apply with self. |
| 287 | if (methodFn !== arrayProto[method as any]) { |
| 288 | const result = methodFn.apply(self, args) |
| 289 | return needsWrap ? toReactive(result) : result |
| 290 | } |
| 291 | |
| 292 | let wrappedFn = fn |
| 293 | if (arr !== self) { |
| 294 | if (needsWrap) { |
| 295 | wrappedFn = function (this: unknown, item, index) { |
| 296 | return fn.call(this, toWrapped(self, item), index, self) |
| 297 | } |
| 298 | } else if (fn.length > 2) { |
| 299 | wrappedFn = function (this: unknown, item, index) { |
| 300 | return fn.call(this, item, index, self) |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | const result = methodFn.call(arr, wrappedFn, thisArg) |
| 305 | return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result |
| 306 | } |
| 307 | |
| 308 | // instrument reduce and reduceRight to take ARRAY_ITERATE dependency |
| 309 | function reduce( |
no test coverage detected