Explorar el Código

fix: make sure global state is restored in the case of an exception in macrotask callback (#9093)

Mitar hace 7 años
padre
commit
b111de486b
Se han modificado 1 ficheros con 5 adiciones y 3 borrados
  1. 5 3
      src/core/util/next-tick.js

+ 5 - 3
src/core/util/next-tick.js

@@ -81,9 +81,11 @@ if (typeof Promise !== 'undefined' && isNative(Promise)) {
 export function withMacroTask (fn: Function): Function {
 export function withMacroTask (fn: Function): Function {
   return fn._withTask || (fn._withTask = function () {
   return fn._withTask || (fn._withTask = function () {
     useMacroTask = true
     useMacroTask = true
-    const res = fn.apply(null, arguments)
-    useMacroTask = false
-    return res
+    try {
+      return fn.apply(null, arguments)
+    } finally {
+      useMacroTask = false    
+    }
   })
   })
 }
 }