Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

[jsfm] add try catch for callback function and event handler #1373

Merged
merged 1 commit into from
Jul 25, 2018
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
6 changes: 5 additions & 1 deletion runtime/bridge/CallbackManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ export default class CallbackManager {
delete this.callbacks[callbackId]
}
if (typeof callback === 'function') {
return callback(data)
try {
return callback.call(null, data)
} catch (error) {
console.error(`[JS Framework] Failed to execute the callback function:\n + ${error.toString()}`)
}
}
return new Error(`invalid callback id "${callbackId}"`)
}
Expand Down
15 changes: 10 additions & 5 deletions runtime/vdom/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,16 @@ export default class Element extends Node {
event.stopPropagation = () => {
isStopPropagation = true
}
if (options && options.params) {
result = handler.call(this, ...options.params, event)
}
else {
result = handler.call(this, event)
try {
if (options && options.params) {
result = handler.call(this, ...options.params, event)
}
else {
result = handler.call(this, event)
}
} catch (error) {
console.error(`[JS Framework] Failed to invoke the event handler of "${type}" `
+ `on ${this.type} (${this.ref}):\n ${error.toString()}`)
}
}

Expand Down