From cd6c568a03b839f2caeebd1103d23364e0fbc461 Mon Sep 17 00:00:00 2001 From: heff Date: Tue, 29 Sep 2015 09:28:02 -0700 Subject: [PATCH] @imbcmdth fix potential triggerReady infinite loop --- src/js/component.js | 6 +++--- test/unit/component.test.js | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/js/component.js b/src/js/component.js index 02cdd13e94..01de2100fd 100644 --- a/src/js/component.js +++ b/src/js/component.js @@ -785,13 +785,13 @@ class Component { this.setTimeout(function(){ let readyQueue = this.readyQueue_; + // Reset Ready Queue + this.readyQueue_ = []; + if (readyQueue && readyQueue.length > 0) { readyQueue.forEach(function(fn){ fn.call(this); }, this); - - // Reset Ready Queue - this.readyQueue_ = []; } // Allow for using event listeners also diff --git a/test/unit/component.test.js b/test/unit/component.test.js index 347a3035a3..391aace87a 100644 --- a/test/unit/component.test.js +++ b/test/unit/component.test.js @@ -419,11 +419,13 @@ test('should not retrigger a listener when the listener calls triggerReady', fun } }; - var comp = new vjs.Component(getFakePlayer(), {}); + var comp = new Component(getFakePlayer(), {}); comp.ready(readyListener); comp.triggerReady(); + this.clock.tick(100); + equal(timesCalled, 1, 'triggerReady from inside a ready handler does not result in an infinite loop'); });