Skip to content

Commit

Permalink
fix(text): Fix VTTCue polyfill in uncompiled mode on Edge
Browse files Browse the repository at this point in the history
The polyfill assigns a static method over window.VTTCue, which is then
called with "new".  This will not work on Edge in uncompiled mode,
since the method is not an old-style "function".

To fix this, we wrap the chosen static method into a "function".

Change-Id: I9b5687e39b3af1bd160e4db4595de06720564a1d
  • Loading branch information
joeyparrish committed Aug 11, 2020
1 parent 565bb7d commit 4499149
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lib/polyfill/vttcue.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,32 @@ shaka.polyfill.VTTCue = class {
return;
}

/** @type {?function(number, number, string):!TextTrackCue} */
let replacement = null;
const constructorLength = TextTrackCue.length;
if (constructorLength == 3) {
shaka.log.info('Using VTTCue polyfill from 3 argument TextTrackCue.');
window['VTTCue'] = shaka.polyfill.VTTCue.from3ArgsTextTrackCue_;
replacement = shaka.polyfill.VTTCue.from3ArgsTextTrackCue_;
} else if (constructorLength == 6) {
shaka.log.info('Using VTTCue polyfill from 6 argument TextTrackCue.');
window['VTTCue'] = shaka.polyfill.VTTCue.from6ArgsTextTrackCue_;
replacement = shaka.polyfill.VTTCue.from6ArgsTextTrackCue_;
} else if (shaka.polyfill.VTTCue.canUse3ArgsTextTrackCue_()) {
shaka.log.info('Using VTTCue polyfill from 3 argument TextTrackCue.');
window['VTTCue'] = shaka.polyfill.VTTCue.from3ArgsTextTrackCue_;
replacement = shaka.polyfill.VTTCue.from3ArgsTextTrackCue_;
}

if (!replacement) {
shaka.log.error('No recognized signature for TextTrackCue found!');
return;
}

// The polyfilled VTTCue must be callable with "new", but the static methods
// in this class cannot be called that way on legacy Edge. So we must wrap
// the replacement in a plain function.
// eslint-disable-next-line no-restricted-syntax
window['VTTCue'] = function(start, end, text) {
return replacement(start, end, text);
};
}

/**
Expand Down

0 comments on commit 4499149

Please sign in to comment.