fix(runtime-core): handle invalid values in callWithAsyncErrorHandling

This commit is contained in:
caomingrui 2024-04-15 22:37:16 +08:00 committed by GitHub
parent 7ccd453dd0
commit 53d15d3f76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 6 deletions

View File

@ -2,7 +2,7 @@ import { pauseTracking, resetTracking } from '@vue/reactivity'
import type { VNode } from './vnode' import type { VNode } from './vnode'
import type { ComponentInternalInstance } from './component' import type { ComponentInternalInstance } from './component'
import { popWarningContext, pushWarningContext, warn } from './warning' import { popWarningContext, pushWarningContext, warn } from './warning'
import { isFunction, isPromise } from '@vue/shared' import { isArray, isFunction, isPromise } from '@vue/shared'
import { LifecycleHooks } from './enums' import { LifecycleHooks } from './enums'
// contexts where user provided function may be executed, in addition to // contexts where user provided function may be executed, in addition to
@ -79,7 +79,7 @@ export function callWithAsyncErrorHandling(
instance: ComponentInternalInstance | null, instance: ComponentInternalInstance | null,
type: ErrorTypes, type: ErrorTypes,
args?: unknown[], args?: unknown[],
): any[] { ): any {
if (isFunction(fn)) { if (isFunction(fn)) {
const res = callWithErrorHandling(fn, instance, type, args) const res = callWithErrorHandling(fn, instance, type, args)
if (res && isPromise(res)) { if (res && isPromise(res)) {
@ -90,11 +90,17 @@ export function callWithAsyncErrorHandling(
return res return res
} }
if (isArray(fn)) {
const values = [] const values = []
for (let i = 0; i < fn.length; i++) { for (let i = 0; i < fn.length; i++) {
values.push(callWithAsyncErrorHandling(fn[i], instance, type, args)) values.push(callWithAsyncErrorHandling(fn[i], instance, type, args))
} }
return values return values
} else if (__DEV__) {
warn(
`Invalid value type passed to callWithAsyncErrorHandling(): ${typeof fn}`,
)
}
} }
export function handleError( export function handleError(