File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change 2
2
/* globals MutationObserver */
3
3
4
4
import { noop } from 'shared/util'
5
+ import { handleError } from './error'
5
6
6
7
// can we use __proto__?
7
8
export const hasProto = '__proto__' in { }
@@ -123,15 +124,22 @@ export const nextTick = (function () {
123
124
return function queueNextTick ( cb ?: Function , ctx ?: Object ) {
124
125
let _resolve
125
126
callbacks . push ( ( ) => {
126
- if ( cb ) cb . call ( ctx )
127
- if ( _resolve ) _resolve ( ctx )
127
+ if ( cb ) {
128
+ try {
129
+ cb . call ( ctx )
130
+ } catch ( e ) {
131
+ handleError ( e , ctx , 'nextTick' )
132
+ }
133
+ } else if ( _resolve ) {
134
+ _resolve ( ctx )
135
+ }
128
136
} )
129
137
if ( ! pending ) {
130
138
pending = true
131
139
timerFunc ( )
132
140
}
133
141
if ( ! cb && typeof Promise !== 'undefined' ) {
134
- return new Promise ( resolve => {
142
+ return new Promise ( ( resolve , reject ) => {
135
143
_resolve = resolve
136
144
} )
137
145
}
Original file line number Diff line number Diff line change @@ -106,6 +106,25 @@ describe('Error handling', () => {
106
106
} ) . then ( done )
107
107
} )
108
108
109
+ it ( 'should capture and recover from nextTick errors' , done => {
110
+ const err1 = new Error ( 'nextTick' )
111
+ const err2 = new Error ( 'nextTick2' )
112
+ const spy = Vue . config . errorHandler = jasmine . createSpy ( 'errorHandler' )
113
+ Vue . nextTick ( ( ) => { throw err1 } )
114
+ Vue . nextTick ( ( ) => {
115
+ expect ( spy ) . toHaveBeenCalledWith ( err1 , undefined , 'nextTick' )
116
+
117
+ const vm = new Vue ( )
118
+ vm . $nextTick ( ( ) => { throw err2 } )
119
+ Vue . nextTick ( ( ) => {
120
+ // should be called with correct instance info
121
+ expect ( spy ) . toHaveBeenCalledWith ( err2 , vm , 'nextTick' )
122
+ Vue . config . errorHandler = null
123
+ done ( )
124
+ } )
125
+ } )
126
+ } )
127
+
109
128
it ( 'properly format component names' , ( ) => {
110
129
const vm = new Vue ( )
111
130
expect ( formatComponentName ( vm ) ) . toBe ( '<Root>' )
You can’t perform that action at this time.
0 commit comments