mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-23 17:27:16 +03:00
0ad9aa3fd9
This fixes several inter-related issues:
1. Catch errors in polyfill installation so that test setup isn't
interrupted half-way through
2. Use the compiled polyfill in tests, fixing polyfill installation
error during tests on IE
3. Require at least version 1.0.2 of the polyfill, since 1.0.0 had
bugs in the module export and 1.0.1 had an infinite recursion bug
Change-Id: I38c973152409d9b3168e70e82f20579566663208
59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
/** @license
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
goog.provide('shaka.polyfill');
|
|
|
|
goog.require('shaka.log');
|
|
goog.require('shaka.util.Iterables');
|
|
|
|
|
|
/**
|
|
* @summary A one-stop installer for all polyfills.
|
|
* @see http://enwp.org/polyfill
|
|
* @exportInterface
|
|
*/
|
|
shaka.polyfill = class {
|
|
/**
|
|
* Install all polyfills.
|
|
* @export
|
|
*/
|
|
static installAll() {
|
|
for (const polyfill of shaka.polyfill.polyfills_) {
|
|
try {
|
|
polyfill.callback();
|
|
} catch (error) {
|
|
shaka.log.alwaysWarn('Error installing polyfill!', error);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Registers a new polyfill to be installed.
|
|
*
|
|
* @param {function()} polyfill
|
|
* @param {number=} priority An optional number priority. Higher priorities
|
|
* will be executed before lower priority ones. Default is 0.
|
|
* @export
|
|
*/
|
|
static register(polyfill, priority) {
|
|
const newItem = {priority: priority || 0, callback: polyfill};
|
|
const enumerate = (it) => shaka.util.Iterables.enumerate(it);
|
|
for (const {i, item} of enumerate(shaka.polyfill.polyfills_)) {
|
|
if (item.priority < newItem.priority) {
|
|
shaka.polyfill.polyfills_.splice(i, 0, newItem);
|
|
return;
|
|
}
|
|
}
|
|
shaka.polyfill.polyfills_.push(newItem);
|
|
}
|
|
};
|
|
|
|
|
|
/**
|
|
* Contains the polyfills that will be installed.
|
|
* @private {!Array.<{priority: number, callback: function()}>}
|
|
*/
|
|
shaka.polyfill.polyfills_ = [];
|