Fix compiled release version of supportsChunkSize.

In the code for supportsChunkSize, we test to see if a given chunk
size is supported by array to string conversion by trying to perform an
operation on a Uint8Array of that size without throwing an error.
However, the result of that operation was only ever referenced inside an
assert. Because asserts are compiled out in release builds, the
result of that operation was not being used... and thus, the entire
call was being compiled out.
This changes the return value of the function to use the result of the
operation, thus preventing it from being compiled out.
This also adds a unit test that will detect this problem in the future.

Closes #2433

Change-Id: If3048531afc460beb16de0dda7f7fcbd5499fdaf
This commit is contained in:
Theodore Abshire
2020-03-06 12:16:09 -08:00
parent 235e4e11ad
commit daa316643a
4 changed files with 5152 additions and 1 deletions
+10 -1
View File
@@ -201,6 +201,15 @@ shaka.util.StringUtils = class {
static fromCharCode(array) {
return shaka.util.StringUtils.fromCharCodeImpl_.value()(array);
}
/**
* Resets the fromCharCode method's implementation.
* For debug use.
* @export
*/
static resetFromCharCode() {
shaka.util.StringUtils.fromCharCodeImpl_.reset();
}
};
@@ -219,7 +228,7 @@ shaka.util.StringUtils.fromCharCodeImpl_ = new shaka.util.Lazy(() => {
// eslint-disable-next-line no-restricted-syntax
const foo = String.fromCharCode.apply(null, buffer);
goog.asserts.assert(foo, 'Should get value');
return true;
return foo.length > 0; // Actually use "foo", so it's not compiled out.
} catch (error) {
return false;
}