Skip to content

Commit

Permalink
Avoid load-time uses of Uint8Array.
Browse files Browse the repository at this point in the history
This is inteded to fix a couple of the load-time exceptions seen
when loading the library on IE9.  Eliminating load-time exceptions
will make it possible to use isBrowserSupported() as intended, to
avoid use of the library on older browsers.

Issue #87

Change-Id: I993d4f955e80a7401bea182ae90df43a8a022ca2
  • Loading branch information
joeyparrish committed Jun 2, 2015
1 parent a38dabf commit 1e400f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
8 changes: 6 additions & 2 deletions lib/polyfill/patchedmediakeys_v01b.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ shaka.polyfill.PatchedMediaKeys.v01b.install = function() {
// Alias.
var v01b = shaka.polyfill.PatchedMediaKeys.v01b;

// Construct fake key ID. This is not done at load-time to avoid exceptions
// on unsupported browsers.
v01b.MediaKeyStatusMap.KEY_ID_ =
shaka.util.Uint8ArrayUtils.fromString('FAKE_KEY_ID');

// Install patches.
Navigator.prototype.requestMediaKeySystemAccess =
v01b.requestMediaKeySystemAccess;
Expand Down Expand Up @@ -889,8 +894,7 @@ shaka.polyfill.PatchedMediaKeys.v01b.MediaKeyStatusMap = function() {
* @const {!Uint8Array}
* @private
*/
shaka.polyfill.PatchedMediaKeys.v01b.MediaKeyStatusMap.KEY_ID_ =
shaka.util.Uint8ArrayUtils.fromString('FAKE_KEY_ID');
shaka.polyfill.PatchedMediaKeys.v01b.MediaKeyStatusMap.KEY_ID_;


/**
Expand Down
25 changes: 16 additions & 9 deletions lib/util/ebml_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,26 @@ shaka.util.EbmlParser = function(dataView) {
this.reader_ = new shaka.util.DataViewReader(
dataView,
shaka.util.DataViewReader.Endianness.BIG_ENDIAN);

// If not already constructed, build a list of EBML dynamic size constants.
// This is not done at load-time to avoid exceptions on unsupported browsers.
if (!shaka.util.EbmlParser.DYNAMIC_SIZES) {
shaka.util.EbmlParser.DYNAMIC_SIZES = [
new Uint8Array([0xff]),
new Uint8Array([0x7f, 0xff]),
new Uint8Array([0x3f, 0xff, 0xff]),
new Uint8Array([0x1f, 0xff, 0xff, 0xff]),
new Uint8Array([0x0f, 0xff, 0xff, 0xff, 0xff]),
new Uint8Array([0x07, 0xff, 0xff, 0xff, 0xff, 0xff]),
new Uint8Array([0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
new Uint8Array([0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])
];
}
};


/** @const {!Array.<!Uint8Array>} */
shaka.util.EbmlParser.DYNAMIC_SIZES = [
new Uint8Array([0xff]),
new Uint8Array([0x7f, 0xff]),
new Uint8Array([0x3f, 0xff, 0xff]),
new Uint8Array([0x1f, 0xff, 0xff, 0xff]),
new Uint8Array([0x0f, 0xff, 0xff, 0xff, 0xff]),
new Uint8Array([0x07, 0xff, 0xff, 0xff, 0xff, 0xff]),
new Uint8Array([0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
new Uint8Array([0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])];
shaka.util.EbmlParser.DYNAMIC_SIZES;


/**
Expand Down

0 comments on commit 1e400f5

Please sign in to comment.