[go: nahoru, domu]

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

Commit

Permalink
[jsfm] add try catch for callback function and event handler (#1373)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanks10100 committed Jul 25, 2018
1 parent a45c0ce commit cb22b8a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
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

0 comments on commit cb22b8a

Please sign in to comment.