Skip to content

Commit

Permalink
fix: avoid uiTextDisplayer.destroy crashing if called more than once (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
antondc committed Jan 8, 2024
1 parent dd50028 commit 42c235d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -21,6 +21,7 @@ Alugha GmbH <*@alugha.com>
Alvaro Velad Galvan <ladvan91@hotmail.com>
Amila Sampath <lucksy@gmail.com>
Anthony Stansbridge <github@anthonystansbridge.co.uk>
Antonio Diaz Correa <hello@antoniodiaz.me>
Armand Zangue <armand.zangue@gmail.com>
Benjamin Wallberg <me@bwallberg.com>
Bonnier Broadcasting <*@bonnierbroadcasting.com>
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Expand Up @@ -32,6 +32,7 @@ Alvaro Velad Galvan <ladvan91@hotmail.com>
Amila Sampath <lucksy@gmail.com>
Andy Hochhaus <ahochhaus@samegoal.com>
Anthony Stansbridge <github@anthonystansbridge.co.uk>
Antonio Diaz Correa <hello@antoniodiaz.me>
Armand Zangue <armand.zangue@gmail.com>
Ashutosh Kumar Mukhiya <ashukm4@gmail.com>
Benjamin Wallberg <benjamin.wallberg@bonnierbroadcasting.com>
Expand Down
7 changes: 7 additions & 0 deletions lib/text/ui_text_displayer.js
Expand Up @@ -154,6 +154,11 @@ shaka.text.UITextDisplayer = class {
* @export
*/
destroy() {
// Return resolved promise if destroy() has been called.
if (!this.textContainer_) {
return Promise.resolve();
}

// Remove the text container element from the UI.
this.videoContainer_.removeChild(this.textContainer_);
this.textContainer_ = null;
Expand All @@ -176,6 +181,8 @@ shaka.text.UITextDisplayer = class {
this.resizeObserver_.disconnect();
this.resizeObserver_ = null;
}

return Promise.resolve();
}


Expand Down
9 changes: 9 additions & 0 deletions test/text/ui_text_displayer_unit.js
Expand Up @@ -605,4 +605,13 @@ describe('UITextDisplayer', () => {
(e) => e.nodeType == Node.ELEMENT_NODE);
expect(childrenOfTwo.length).toBe(3);
});

it('textDisplayer does not crash if destroy is called more than once', () => {
expect(videoContainer.childNodes.length).toBe(1);

textDisplayer.destroy();
textDisplayer.destroy();

expect(videoContainer.childNodes.length).toBe(0);
});
});

0 comments on commit 42c235d

Please sign in to comment.