Source: lib/polyfill/all.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.provide('shaka.polyfill');
  7. goog.require('shaka.log');
  8. /**
  9. * @summary A one-stop installer for all polyfills.
  10. * @see http://enwp.org/polyfill
  11. * @export
  12. */
  13. shaka.polyfill = class {
  14. /**
  15. * Install all polyfills.
  16. * @export
  17. */
  18. static installAll() {
  19. for (const polyfill of shaka.polyfill.polyfills_) {
  20. try {
  21. polyfill.callback();
  22. } catch (error) {
  23. shaka.log.alwaysWarn('Error installing polyfill!', error);
  24. }
  25. }
  26. }
  27. /**
  28. * Registers a new polyfill to be installed.
  29. *
  30. * @param {function()} polyfill
  31. * @param {number=} priority An optional number priority. Higher priorities
  32. * will be executed before lower priority ones. Default is 0.
  33. * @export
  34. */
  35. static register(polyfill, priority) {
  36. const newItem = {priority: priority || 0, callback: polyfill};
  37. for (let i = 0; i < shaka.polyfill.polyfills_.length; i++) {
  38. const item = shaka.polyfill.polyfills_[i];
  39. if (item.priority < newItem.priority) {
  40. shaka.polyfill.polyfills_.splice(i, 0, newItem);
  41. return;
  42. }
  43. }
  44. shaka.polyfill.polyfills_.push(newItem);
  45. }
  46. };
  47. /**
  48. * Contains the polyfills that will be installed.
  49. * @private {!Array<{priority: number, callback: function()}>}
  50. */
  51. shaka.polyfill.polyfills_ = [];