1
0
mirror of https://github.com/videojs/video.js.git synced 2025-02-02 11:34:50 +02:00

@imbcmdth Added exception handling to event dispatcher. closes #3580

* Guard against exceptions in an event handler to stop them from breaking further processing of event handlers

* Added a test for try/catch behavior for exceptions originating in event handlers
This commit is contained in:
Jon-Carlos Rivera 2016-08-25 19:08:56 -04:00 committed by GitHub
parent eff1cf34db
commit fdd8550307
3 changed files with 27 additions and 4 deletions

View File

@ -2,7 +2,7 @@ CHANGELOG
=========
## HEAD (Unreleased)
_(none)_
* @imbcmdth Added exception handling to event dispatcher ([view](https://github.com/videojs/video.js/pull/3580))
--------------------

View File

@ -7,8 +7,9 @@
* robust as jquery's, so there's probably some differences.
*/
import * as Dom from './dom.js';
import * as Guid from './guid.js';
import * as Dom from './dom.js';
import * as Guid from './guid.js';
import log from './log.js';
import window from 'global/window';
import document from 'global/document';
@ -57,7 +58,11 @@ export function on(elem, type, fn){
if (event.isImmediatePropagationStopped()) {
break;
} else {
handlersCopy[m].call(elem, event, hash);
try {
handlersCopy[m].call(elem, event, hash);
} catch (e) {
log.error(e);
}
}
}
}

View File

@ -239,3 +239,21 @@ test('should have relatedTarget correctly set on the event', function() {
Events.trigger(el2, { type:'click', relatedTarget:undefined });
});
QUnit.test('should execute remaining handlers after an exception in an event handler', function(assert) {
assert.expect(1);
const el = document.createElement('div');
const listener1 = function() {
throw new Error('GURU MEDITATION ERROR');
};
const listener2 = function() {
assert.ok(true, 'Click Triggered');
};
Events.on(el, 'click', listener1);
Events.on(el, 'click', listener2);
// 1 click
Events.trigger(el, 'click');
});