Source: lib/polyfill/symbol.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.provide('shaka.polyfill.Symbol');
  7. goog.require('shaka.log');
  8. goog.require('shaka.polyfill');
  9. /**
  10. * @summary A polyfill to provide Symbol.prototype.description in all browsers.
  11. * See: https://caniuse.com/mdn-javascript_builtins_symbol_description
  12. * @export
  13. */
  14. shaka.polyfill.Symbol = class {
  15. /**
  16. * Install the polyfill if needed.
  17. * @export
  18. */
  19. static install() {
  20. shaka.log.debug('Symbol.install');
  21. // eslint-disable-next-line no-restricted-syntax
  22. const proto = Symbol.prototype;
  23. if (!('description' in proto)) {
  24. Object.defineProperty(proto, 'description', {
  25. get: shaka.polyfill.Symbol.getSymbolDescription_,
  26. });
  27. }
  28. }
  29. /**
  30. * @this {Symbol}
  31. * @return {(string|undefined)}
  32. * @private
  33. */
  34. static getSymbolDescription_() {
  35. const m = /\((.*)\)/.exec(this.toString());
  36. return m ? m[1] : undefined;
  37. }
  38. };
  39. shaka.polyfill.register(shaka.polyfill.Symbol.install);