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

fix(middleware): do a null check in mediator methods (#4913)

This commit is contained in:
Gary Katsevman 2018-01-31 10:46:58 -05:00 committed by GitHub
parent 4404e071ba
commit 7670db63cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -96,7 +96,9 @@ function executeRight(mws, method, value, terminated) {
for (let i = mws.length - 1; i >= 0; i--) {
const mw = mws[i];
mw[method](terminated, value);
if (mw[method]) {
mw[method](terminated, value);
}
}
}

View File

@ -394,3 +394,18 @@ QUnit.test('setSource will select all middleware of a given type, until src chan
middleware.getMiddleware('video/foo').pop();
middleware.getMiddleware('video/foo').pop();
});
QUnit.test('a middleware without a mediator method will not throw an error', function(assert) {
let pauseCalled = 0;
const myMw = {};
const mwFactory = () => myMw;
const mwFactory2 = () => ({
pause() {
pauseCalled++;
}
});
middleware.mediate([mwFactory(), mwFactory2()], {pause: () => {}}, 'pause');
assert.equal(pauseCalled, 1, 'pauseCalled was called once and no error was thrown');
});