From 400575498f34cf252aaba0bc1367953b8cf44537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Wed, 30 Mar 2022 01:04:26 +0200 Subject: [PATCH] fix(cmcd): Fix Symbol usage in CMCD on Xbox One (#4073) Close #4072 Co-authored-by: Joey Parrish --- build/types/polyfill | 1 + lib/polyfill/symbol.js | 46 ++++++++++++++++++++++++++++++++++++++ shaka-player.uncompiled.js | 1 + 3 files changed, 48 insertions(+) create mode 100644 lib/polyfill/symbol.js diff --git a/build/types/polyfill b/build/types/polyfill index f54e383ae6..0559a70fca 100644 --- a/build/types/polyfill +++ b/build/types/polyfill @@ -15,6 +15,7 @@ +../../lib/polyfill/pip_webkit.js +../../lib/polyfill/random_uuid.js +../../lib/polyfill/storage_estimate.js ++../../lib/polyfill/symbol.js +../../lib/polyfill/video_play_promise.js +../../lib/polyfill/videoplaybackquality.js +../../lib/polyfill/vttcue.js diff --git a/lib/polyfill/symbol.js b/lib/polyfill/symbol.js new file mode 100644 index 0000000000..36135d1fdf --- /dev/null +++ b/lib/polyfill/symbol.js @@ -0,0 +1,46 @@ +/*! @license + * Shaka Player + * Copyright 2016 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ +goog.provide('shaka.polyfill.Symbol'); + +goog.require('shaka.log'); +goog.require('shaka.polyfill'); + +/** + * @summary A polyfill to provide Symbol.prototype.description in all browsers. + * See: https://caniuse.com/mdn-javascript_builtins_symbol_description + * @export + */ +shaka.polyfill.Symbol = class { + /** + * Install the polyfill if needed. + * @export + */ + static install() { + shaka.log.debug('Symbol.install'); + + // eslint-disable-next-line no-restricted-syntax + const proto = Symbol.prototype; + + if (!('description' in proto)) { + Object.defineProperty(proto, 'description', { + get: shaka.polyfill.Symbol.getSymbolDescription_, + }); + } + } + + /** + * @this {Symbol} + * @return {(string|undefined)} + * @private + */ + static getSymbolDescription_() { + const m = /\((.*)\)/.exec(this.toString()); + return m ? m[1] : undefined; + } +}; + + +shaka.polyfill.register(shaka.polyfill.Symbol.install); diff --git a/shaka-player.uncompiled.js b/shaka-player.uncompiled.js index 909b7bfffb..10b3ef7285 100644 --- a/shaka-player.uncompiled.js +++ b/shaka-player.uncompiled.js @@ -45,6 +45,7 @@ goog.require('shaka.polyfill.PatchedMediaKeysNop'); goog.require('shaka.polyfill.PatchedMediaKeysWebkit'); goog.require('shaka.polyfill.PiPWebkit'); goog.require('shaka.polyfill.RandomUUID'); +goog.require('shaka.polyfill.Symbol'); goog.require('shaka.polyfill.VTTCue'); goog.require('shaka.polyfill.VideoPlayPromise'); goog.require('shaka.polyfill.VideoPlaybackQuality');