Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cmcd): Fix Symbol usage in CMCD on Xbox One #4073

Merged
merged 2 commits into from Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions build/types/polyfill
Expand Up @@ -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
39 changes: 39 additions & 0 deletions 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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this in an arrow function refers to the enclosing scope, here meaning the this of install(), which I believe is shaka.polyfill.Symbol.

I think you'll need to replace this arrow function with a function or method.

I have tested toString() and the regex on Xbox, and it should work otherwise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the liberty of making an edit to resolve this. I then tested it on Xbox, and the tests are passing.

return m ? m[1] : undefined;
},
});
}
}
};


shaka.polyfill.register(shaka.polyfill.Symbol.install);
1 change: 1 addition & 0 deletions shaka-player.uncompiled.js
Expand Up @@ -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');
Expand Down