]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: pass target instance to errorCaptured hook
authorEvan You <yyx990803@gmail.com>
Wed, 3 Oct 2018 17:03:37 +0000 (13:03 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 3 Oct 2018 17:03:37 +0000 (13:03 -0400)
packages/core/src/component.ts
packages/core/src/errorHandling.ts

index 3cd9ea97ec468c1bae5eb8a55946a00c097e51c5..b010e83627e50e46cfe89a9c27e2823971ac7579 100644 (file)
@@ -55,7 +55,11 @@ export interface MountedComponent<D = Data, P = Data>
   updated?(vnode: VNode): void
   beforeUnmount?(): void
   unmounted?(): void
-  errorCaptured?(): (err: Error, type: ErrorTypes) => boolean | void
+  errorCaptured?(): (
+    err: Error,
+    type: ErrorTypes,
+    target: MountedComponent
+  ) => boolean | void
   activated?(): void
   deactivated?(): void
 
index 9294ab5023941cb69dd41245a8e5450d62f646ed..b6d040f7267596c0247c1a1b37d40379ce45f55c 100644 (file)
@@ -45,17 +45,17 @@ export function handleError(
     const handler = cur.errorCaptured
     if (handler) {
       try {
-        const captured = handler.call(cur, err, type)
+        const captured = handler.call(cur, err, type, instance)
         if (captured) return
       } catch (err2) {
-        logError(err2, cur, ErrorTypes.ERROR_CAPTURED)
+        logError(err2, ErrorTypes.ERROR_CAPTURED)
       }
     }
   }
-  logError(err, instance, type)
+  logError(err, type)
 }
 
-function logError(err: Error, instance: MountedComponent, type: ErrorTypes) {
+function logError(err: Error, type: ErrorTypes) {
   if (__DEV__) {
     const info = ErrorTypeStrings[type]
     console.warn(`Unhandled error${info ? ` in ${info}` : ``}:`)