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: ensure cleanup in watcher.get #5988

Merged
merged 1 commit into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
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
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')
})
})