mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 17:48:07 +02:00
Remove most assert()
calls (issue 8506)
This replaces `assert` calls with `throw new FormatError()`/`throw new Error()`. In a few places, throwing an `Error` (which is what `assert` meant) isn't correct since the enclosing function is supposed to return a `Promise`, hence some cases were changed to `Promise.reject(...)` and similarily for `createPromiseCapability` instances.
This commit is contained in:
parent
09f04eccda
commit
814fa1dee3
12 changed files with 193 additions and 89 deletions
|
@ -14,8 +14,8 @@
|
|||
*/
|
||||
|
||||
import {
|
||||
arrayByteLength, arraysToBytes, assert, createPromiseCapability, isEmptyObj,
|
||||
isInt, MissingDataException
|
||||
arrayByteLength, arraysToBytes, createPromiseCapability, isEmptyObj, isInt,
|
||||
MissingDataException
|
||||
} from '../shared/util';
|
||||
|
||||
var ChunkedStream = (function ChunkedStreamClosure() {
|
||||
|
@ -58,12 +58,15 @@ var ChunkedStream = (function ChunkedStreamClosure() {
|
|||
onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
|
||||
var end = begin + chunk.byteLength;
|
||||
|
||||
assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
|
||||
if (begin % this.chunkSize !== 0) {
|
||||
throw new Error(`Bad begin offset: ${begin}`);
|
||||
}
|
||||
// Using this.length is inaccurate here since this.start can be moved
|
||||
// See ChunkedStream.moveStart()
|
||||
var length = this.bytes.length;
|
||||
assert(end % this.chunkSize === 0 || end === length,
|
||||
'Bad end offset: ' + end);
|
||||
if (end % this.chunkSize !== 0 && end !== length) {
|
||||
throw new Error(`Bad end offset: ${end}`);
|
||||
}
|
||||
|
||||
this.bytes.set(new Uint8Array(chunk), begin);
|
||||
var chunkSize = this.chunkSize;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue