From 53d15d3f76184eed67a18d35e43d9a2062f8e121 Mon Sep 17 00:00:00 2001 From: caomingrui <47497092+caomingrui@users.noreply.github.com> Date: Mon, 15 Apr 2024 22:37:16 +0800 Subject: [PATCH] fix(runtime-core): handle invalid values in callWithAsyncErrorHandling --- packages/runtime-core/src/errorHandling.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/runtime-core/src/errorHandling.ts b/packages/runtime-core/src/errorHandling.ts index dda6480385b..41c92cbd34a 100644 --- a/packages/runtime-core/src/errorHandling.ts +++ b/packages/runtime-core/src/errorHandling.ts @@ -2,7 +2,7 @@ import { pauseTracking, resetTracking } from '@vue/reactivity' import type { VNode } from './vnode' import type { ComponentInternalInstance } from './component' import { popWarningContext, pushWarningContext, warn } from './warning' -import { isFunction, isPromise } from '@vue/shared' +import { isArray, isFunction, isPromise } from '@vue/shared' import { LifecycleHooks } from './enums' // contexts where user provided function may be executed, in addition to @@ -79,7 +79,7 @@ export function callWithAsyncErrorHandling( instance: ComponentInternalInstance | null, type: ErrorTypes, args?: unknown[], -): any[] { +): any { if (isFunction(fn)) { const res = callWithErrorHandling(fn, instance, type, args) if (res && isPromise(res)) { @@ -90,11 +90,17 @@ export function callWithAsyncErrorHandling( return res } - const values = [] - for (let i = 0; i < fn.length; i++) { - values.push(callWithAsyncErrorHandling(fn[i], instance, type, args)) + if (isArray(fn)) { + const values = [] + for (let i = 0; i < fn.length; i++) { + values.push(callWithAsyncErrorHandling(fn[i], instance, type, args)) + } + return values + } else if (__DEV__) { + warn( + `Invalid value type passed to callWithAsyncErrorHandling(): ${typeof fn}`, + ) } - return values } export function handleError(