Clean up EBML size constants

Instead of using an array of Uint8Arrays, which could trigger a
load-time failure on very old browsers, store an array of number
arrays.  This is equivalent for the purpose of comparison, and it
cannot fail at load-time.

This cleanup seems to fix minor test flake in the EBML parser tests
that was observed with upgraded node modules.

Issue #1694

Change-Id: I87b2307bceddb3a21dfc81d4fe9828afd9508617
This commit is contained in:
Joey Parrish
2019-05-15 12:30:40 -07:00
parent 3adde6a28d
commit ea4d941f39
2 changed files with 22 additions and 22 deletions
+17 -20
View File
@@ -37,26 +37,23 @@ 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;
/**
* A list of EBML dynamic size constants.
* @const {!Array.<!Array.<number>>}
*/
shaka.util.EbmlParser.DYNAMIC_SIZES = [
[0xff],
[0x7f, 0xff],
[0x3f, 0xff, 0xff],
[0x1f, 0xff, 0xff, 0xff],
[0x0f, 0xff, 0xff, 0xff, 0xff],
[0x07, 0xff, 0xff, 0xff, 0xff, 0xff],
[0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
[0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
];
/**
@@ -225,10 +222,10 @@ shaka.util.EbmlParser.getVintValue_ = function(vint) {
*/
shaka.util.EbmlParser.isDynamicSizeValue_ = function(vint) {
const EbmlParser = shaka.util.EbmlParser;
const uint8ArrayEqual = shaka.util.Uint8ArrayUtils.equal;
const Uint8ArrayUtils = shaka.util.Uint8ArrayUtils;
for (let i = 0; i < EbmlParser.DYNAMIC_SIZES.length; i++) {
if (uint8ArrayEqual(vint, EbmlParser.DYNAMIC_SIZES[i])) {
for (const dynamicSizeConst of EbmlParser.DYNAMIC_SIZES) {
if (Uint8ArrayUtils.equal(vint, dynamicSizeConst)) {
return true;
}
}
+5 -2
View File
@@ -109,8 +109,11 @@ shaka.util.Uint8ArrayUtils.toHex = function(arr) {
/**
* Compare two Uint8Arrays for equality.
* @param {Uint8Array} arr1
* @param {Uint8Array} arr2
* For convenience, this also accepts Arrays, so that one can trivially compare
* a Uint8Array to an Array of numbers.
*
* @param {(Uint8Array|Array.<number>)} arr1
* @param {(Uint8Array|Array.<number>)} arr2
* @return {boolean}
* @export
*/