From dcf2a300eff3a0f71450da59fcb05a687093c7d7 Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Thu, 14 Jan 2016 14:01:30 -0500 Subject: [PATCH] make sure that styleEl_ is in DOM before removing on dispose. closes #3004 --- CHANGELOG.md | 2 +- src/js/player.js | 2 +- test/unit/player.test.js | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db1e91dd1..ca8aaf135 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ CHANGELOG ========= ## HEAD (Unreleased) -_(none)_ +* make sure that styleEl_ is in DOM before removing on dispose ([view](https://github.com/videojs/video.js/pull/3004)) -------------------- diff --git a/src/js/player.js b/src/js/player.js index df5128b4c..5fcb09486 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -224,7 +224,7 @@ class Player extends Component { // prevent dispose from being called twice this.off('dispose'); - if (this.styleEl_) { + if (this.styleEl_ && this.styleEl_.parentNode) { this.styleEl_.parentNode.removeChild(this.styleEl_); } diff --git a/test/unit/player.test.js b/test/unit/player.test.js index a287a8769..c2f7725dd 100644 --- a/test/unit/player.test.js +++ b/test/unit/player.test.js @@ -30,6 +30,15 @@ test('should create player instance that inherits from component and dispose it' ok(player.el() === null, 'element disposed'); }); +test('dispose should not throw if styleEl is missing', function(){ + var player = TestHelpers.makePlayer(); + + player.styleEl_.parentNode.removeChild(player.styleEl_); + + player.dispose(); + ok(player.el() === null, 'element disposed'); +}); + // technically, all uses of videojs.options should be replaced with // Player.prototype.options_ in this file and a equivalent test using // videojs.options should be made in video.test.js. Keeping this here