From d5792808313314f0cf5e5fb3d81027602e087c25 Mon Sep 17 00:00:00 2001 From: Alvaro Velad Date: Tue, 29 Mar 2022 14:51:53 +0200 Subject: [PATCH 1/2] fix(cmcd): Add Symbol.prototype.description polyfill --- build/types/polyfill | 1 + lib/polyfill/symbol.js | 39 ++++++++++++++++++++++++++++++++++++++ shaka-player.uncompiled.js | 1 + 3 files changed, 41 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..234f73860a --- /dev/null +++ b/lib/polyfill/symbol.js @@ -0,0 +1,39 @@ +/*! @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: () => { + 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'); From cfd2c661a50741a510287a1c7509a29b8143dc98 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Tue, 29 Mar 2022 15:47:44 -0700 Subject: [PATCH 2/2] Move Symbol description getter to static method This resolves both the use of `this` in an arrow function and compiler issues with the type of `this`. --- lib/polyfill/symbol.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/polyfill/symbol.js b/lib/polyfill/symbol.js index 234f73860a..36135d1fdf 100644 --- a/lib/polyfill/symbol.js +++ b/lib/polyfill/symbol.js @@ -26,13 +26,20 @@ shaka.polyfill.Symbol = class { if (!('description' in proto)) { Object.defineProperty(proto, 'description', { - get: () => { - const m = /\((.*)\)/.exec(this.toString()); - return m ? m[1] : undefined; - }, + get: shaka.polyfill.Symbol.getSymbolDescription_, }); } } + + /** + * @this {Symbol} + * @return {(string|undefined)} + * @private + */ + static getSymbolDescription_() { + const m = /\((.*)\)/.exec(this.toString()); + return m ? m[1] : undefined; + } };