Source: lib/polyfill/all.js

  1. /**
  2. * @license
  3. * Copyright 2016 Google Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. goog.provide('shaka.polyfill.installAll');
  18. goog.provide('shaka.polyfill.register');
  19. /**
  20. * @namespace shaka.polyfill
  21. * @summary A one-stop installer for all polyfills.
  22. * @see http://enwp.org/polyfill
  23. * @exportDoc
  24. */
  25. /**
  26. * Install all polyfills.
  27. * @export
  28. */
  29. shaka.polyfill.installAll = function() {
  30. for (let i = 0; i < shaka.polyfill.polyfills_.length; ++i) {
  31. shaka.polyfill.polyfills_[i].callback();
  32. }
  33. };
  34. /**
  35. * Contains the polyfills that will be installed.
  36. * @private {!Array.<{priority: number, callback: function()}>}
  37. */
  38. shaka.polyfill.polyfills_ = [];
  39. /**
  40. * Registers a new polyfill to be installed.
  41. *
  42. * @param {function()} polyfill
  43. * @param {number=} priority An optional number priority. Higher priorities
  44. * will be executed before lower priority ones. Default is 0.
  45. * @export
  46. */
  47. shaka.polyfill.register = function(polyfill, priority) {
  48. priority = priority || 0;
  49. const item = {priority: priority, callback: polyfill};
  50. for (let i = 0; i < shaka.polyfill.polyfills_.length; i++) {
  51. if (shaka.polyfill.polyfills_[i].priority < priority) {
  52. shaka.polyfill.polyfills_.splice(i, 0, item);
  53. return;
  54. }
  55. }
  56. shaka.polyfill.polyfills_.push(item);
  57. };