Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fn添加数组校验 #10482

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions packages/runtime-core/src/errorHandling.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
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
Expand Down Expand Up @@ -78,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)) {
Expand All @@ -89,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(
Expand Down Expand Up @@ -127,12 +134,14 @@ export function handleError(
// app-level handling
const appErrorHandler = instance.appContext.config.errorHandler
if (appErrorHandler) {
pauseTracking()
callWithErrorHandling(
appErrorHandler,
null,
ErrorCodes.APP_ERROR_HANDLER,
[err, exposedInstance, errorInfo],
)
resetTracking()
return
}
}
Expand Down