mirror of
https://github.com/videojs/video.js.git
synced 2025-01-04 06:48:49 +02:00
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.
This commit is contained in:
parent
c340dbcccd
commit
e12bedbb45
@ -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];
|
||||
}
|
||||
|
@ -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'
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user