From e12bedbb45c510de2ca70cb93e1cbd7718e911c3 Mon Sep 17 00:00:00 2001 From: Pat O'Neill Date: Wed, 18 Jan 2017 00:29:27 -0500 Subject: [PATCH] refactor: Remove TimeRanges without an index deprecation warning (#3827) This aligns the methods with the spec. BREAKING CHANGE: removing ability to use TimeRange methods without an index. --- src/js/utils/time-ranges.js | 9 ++------- test/unit/utils/time-ranges.test.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/js/utils/time-ranges.js b/src/js/utils/time-ranges.js index e63282217b..e848eade4a 100644 --- a/src/js/utils/time-ranges.js +++ b/src/js/utils/time-ranges.js @@ -2,7 +2,6 @@ * @file time-ranges.js * @module time-ranges */ -import log from './log.js'; /** * Returns the time for the specified index at the start or end @@ -51,8 +50,8 @@ import log from './log.js'; * @throws {Error} if the timeRanges provided are over the maxIndex */ function rangeCheck(fnName, index, maxIndex) { - if (index < 0 || index > maxIndex) { - throw new Error(`Failed to execute '${fnName}' on 'TimeRanges': The index provided (${index}) is greater than or equal to the maximum bound (${maxIndex}).`); + if (typeof index !== 'number' || index < 0 || index > maxIndex) { + throw new Error(`Failed to execute '${fnName}' on 'TimeRanges': The index provided (${index}) is non-numeric or out of bounds (0-${maxIndex}).`); } } @@ -79,10 +78,6 @@ function rangeCheck(fnName, index, maxIndex) { * @throws {Error} if rangeIndex is more than the length of ranges */ function getRange(fnName, valueIndex, ranges, rangeIndex) { - if (rangeIndex === undefined) { - log.warn(`DEPRECATED: Function '${fnName}' on 'TimeRanges' called without an index argument.`); - rangeIndex = 0; - } rangeCheck(fnName, rangeIndex, ranges.length - 1); return ranges[rangeIndex][valueIndex]; } diff --git a/test/unit/utils/time-ranges.test.js b/test/unit/utils/time-ranges.test.js index 8971cedd5a..68815b5ae1 100644 --- a/test/unit/utils/time-ranges.test.js +++ b/test/unit/utils/time-ranges.test.js @@ -43,3 +43,22 @@ QUnit.test('should create a fake multiple timerange', function(assert) { /Failed to execute 'end'/, 'fails if end is called with with an invalid index'); }); + +QUnit.test('should throw without being given an index', function(assert) { + const tr = createTimeRanges([ + [0, 10], + [11, 20] + ]); + + assert.throws( + () => tr.start(), + /Failed to execute 'start'/, + 'start throws if no index is given' + ); + + assert.throws( + () => tr.end(), + /Failed to execute 'end'/, + 'end throws if no index is given' + ); +});