-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Exceptions in event handlers breaks further processing of event handlers #3580
Conversation
@@ -248,7 +249,11 @@ export function on(elem, type, fn) { | |||
if (event.isImmediatePropagationStopped()) { | |||
break; | |||
} else { | |||
handlersCopy[m].call(elem, event, hash); | |||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this try/catch should probably be wrapped in an IIFE because try/catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would make the code a lot uglier than it already is for little to no benefit. There should never be so many event handlers for any single event that the performance difference becomes an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I lean towards leaving this as-is.
…ng further processing of event handlers
1b0990a
to
5373966
Compare
|
||
const el = document.createElement('div'); | ||
const listener1 = function() { | ||
throw new Error('GURU MEDITATION ERROR'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet.
LGTM |
Description
In the event dispatch function, we do not guard against event handlers raising exceptions. If that happens, any further processing of event handlers and any code after the trigger stops as the exception continues to unwind the stack.
This is particularly problematic if the event was triggered by a source handler during the initialization stages of the handler. The SourceHandler can end up in a state from which it can not recover through no fault of our own.
See this example of a player broken by a simple exception thrown from an event handler:
http://jsbin.com/fipikerore/edit?html,output
Specific Changes proposed
Simply add a try/catch around each invocation of an event handler function called from the the
dispatch
function.Requirements Checklist