Skip to content

Commit

Permalink
fix: ensure cleanup in watcher.get (#5988)
Browse files Browse the repository at this point in the history
watcher.get should always clean up observee stack in order to prevent memory leak. Also, non-user
defined watch should rethrow error.

fix #5975
  • Loading branch information
HerringtonDarkholme authored and yyx990803 committed Jun 29, 2017
1 parent 5581654 commit f6cd44c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/core/observer/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,23 @@ export default class Watcher {
pushTarget(this)
let value
const vm = this.vm
if (this.user) {
try {
value = this.getter.call(vm, vm)
} catch (e) {
try {
value = this.getter.call(vm, vm)
} catch (e) {
if (this.user) {
handleError(e, vm, `getter for watcher "${this.expression}"`)
} else {
throw e
}
} else {
value = this.getter.call(vm, vm)
}
// "touch" every property so they are all tracked as
// dependencies for deep watching
if (this.deep) {
traverse(value)
} finally {
// "touch" every property so they are all tracked as
// dependencies for deep watching
if (this.deep) {
traverse(value)
}
popTarget()
this.cleanupDeps()
}
popTarget()
this.cleanupDeps()
return value
}

Expand Down
11 changes: 11 additions & 0 deletions test/unit/features/options/computed.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,15 @@ describe('Options computed', () => {
})
expect(`computed property "a" is already defined as a prop`).toHaveBeenWarned()
})

it('rethrow computed error', () => {
const vm = new Vue({
computed: {
a: () => {
throw new Error('rethrow')
}
}
})
expect(() => vm.a).toThrowError('rethrow')
})
})

0 comments on commit f6cd44c

Please sign in to comment.