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:
parent
eff1cf34db
commit
fdd8550307
@ -2,7 +2,7 @@ CHANGELOG
|
||||
=========
|
||||
|
||||
## HEAD (Unreleased)
|
||||
_(none)_
|
||||
* @imbcmdth Added exception handling to event dispatcher ([view](https://github.com/videojs/video.js/pull/3580))
|
||||
|
||||
--------------------
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user