Skip to content

Commit

Permalink
fix: Fix compiler error on static use of "this" (#4699)
Browse files Browse the repository at this point in the history
An internal build system failed to compile v4.3.0 due to the use of
static "this". This change fixes it.

Unfortunately, we are already running the latest public compiler
release, so there is no way we could have caught this on GitHub.
  • Loading branch information
joeyparrish committed Dec 8, 2022
1 parent 70e24fd commit 0e2a12a
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions lib/polyfill/patchedmediakeys_apple.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,39 @@ goog.require('shaka.util.StringUtils');
shaka.polyfill.PatchedMediaKeysApple = class {
/**
* Installs the polyfill if needed.
* @param {boolean} enableUninstall enables uninstalling the polyfill
* @param {boolean=} enableUninstall enables uninstalling the polyfill
* @export
*/
static install(enableUninstall = false) {
// Alias
const PatchedMediaKeysApple = shaka.polyfill.PatchedMediaKeysApple;

if (!window.HTMLVideoElement || !window.WebKitMediaKeys) {
// No HTML5 video or no prefixed EME.
return;
}

if (enableUninstall) {
this.enableUninstall = true;
this.originalHTMLMediaElementPrototypeMediaKeys =
PatchedMediaKeysApple.enableUninstall = true;
PatchedMediaKeysApple.originalHTMLMediaElementPrototypeMediaKeys =
/** @type {!Object} */ (
Object.getOwnPropertyDescriptor(
// eslint-disable-next-line no-restricted-syntax
HTMLMediaElement.prototype, 'mediaKeys',
)
);
// eslint-disable-next-line no-restricted-syntax
this.originalHTMLMediaElementPrototypeSetMediaKeys = HTMLMediaElement
.prototype.setMediaKeys;
this.originalWindowMediaKeys = window.MediaKeys;
this.originalWindowMediaKeySystemAccess = window.MediaKeySystemAccess;
this.originalNavigatorRequestMediaKeySystemAccess = navigator
.requestMediaKeySystemAccess;
PatchedMediaKeysApple.originalHTMLMediaElementPrototypeSetMediaKeys =
// eslint-disable-next-line no-restricted-syntax
HTMLMediaElement.prototype.setMediaKeys;
PatchedMediaKeysApple.originalWindowMediaKeys = window.MediaKeys;
PatchedMediaKeysApple.originalWindowMediaKeySystemAccess =
window.MediaKeySystemAccess;
PatchedMediaKeysApple.originalNavigatorRequestMediaKeySystemAccess =
navigator.requestMediaKeySystemAccess;
}

shaka.log.info('Using Apple-prefixed EME');

// Alias
const PatchedMediaKeysApple = shaka.polyfill.PatchedMediaKeysApple;

// Delete mediaKeys to work around strict mode compatibility issues.
// eslint-disable-next-line no-restricted-syntax
delete HTMLMediaElement.prototype['mediaKeys'];
Expand All @@ -83,32 +84,36 @@ shaka.polyfill.PatchedMediaKeysApple = class {
* @export
*/
static uninstall() {
if (!this.enableUninstall) {
// Alias
const PatchedMediaKeysApple = shaka.polyfill.PatchedMediaKeysApple;

if (!PatchedMediaKeysApple.enableUninstall) {
return;
}

shaka.log.info('Un-installing Apple-prefixed EME');

this.enableUninstall = false;
PatchedMediaKeysApple.enableUninstall = false;
Object.defineProperty(
// eslint-disable-next-line no-restricted-syntax
HTMLMediaElement.prototype,
'mediaKeys',
this.originalHTMLMediaElementPrototypeMediaKeys,
PatchedMediaKeysApple.originalHTMLMediaElementPrototypeMediaKeys,
);
// eslint-disable-next-line no-restricted-syntax
HTMLMediaElement.prototype.setMediaKeys = this
.originalHTMLMediaElementPrototypeSetMediaKeys;
window.MediaKeys = this.originalWindowMediaKeys;
window.MediaKeySystemAccess = this.originalWindowMediaKeySystemAccess;
navigator.requestMediaKeySystemAccess = this
.originalNavigatorRequestMediaKeySystemAccess;

this.originalWindowMediaKeys = null;
this.originalWindowMediaKeySystemAccess = null;
this.originalHTMLMediaElementPrototypeSetMediaKeys = null;
this.originalNavigatorRequestMediaKeySystemAccess = null;
this.originalHTMLMediaElementPrototypeMediaKeys = null;
HTMLMediaElement.prototype.setMediaKeys =
PatchedMediaKeysApple.originalHTMLMediaElementPrototypeSetMediaKeys;
window.MediaKeys = PatchedMediaKeysApple.originalWindowMediaKeys;
window.MediaKeySystemAccess =
PatchedMediaKeysApple.originalWindowMediaKeySystemAccess;
navigator.requestMediaKeySystemAccess =
PatchedMediaKeysApple.originalNavigatorRequestMediaKeySystemAccess;

PatchedMediaKeysApple.originalWindowMediaKeys = null;
PatchedMediaKeysApple.originalWindowMediaKeySystemAccess = null;
PatchedMediaKeysApple.originalHTMLMediaElementPrototypeSetMediaKeys = null;
PatchedMediaKeysApple.originalNavigatorRequestMediaKeySystemAccess = null;
PatchedMediaKeysApple.originalHTMLMediaElementPrototypeMediaKeys = null;

window.shakaMediaKeysPolyfill = false;
}
Expand Down

0 comments on commit 0e2a12a

Please sign in to comment.