1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 01:58:06 +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:
Jonas Jenwald 2017-07-20 14:04:54 +02:00
parent 09f04eccda
commit 814fa1dee3
12 changed files with 193 additions and 89 deletions

View file

@ -13,13 +13,12 @@
* limitations under the License.
*/
import {
assert, info, isArray, isArrayBuffer, isNum, isSpace, isString,
MissingDataException, OPS, shadow, stringToBytes, stringToPDFString, Util,
warn
} from '../shared/util';
import { Catalog, ObjectLoader, XRef } from './obj';
import { Dict, isDict, isName, isStream } from './primitives';
import {
info, isArray, isArrayBuffer, isNum, isSpace, isString, MissingDataException,
OPS, shadow, stringToBytes, stringToPDFString, Util, warn
} from '../shared/util';
import { NullStream, Stream, StreamsSequenceStream } from './stream';
import { OperatorList, PartialEvaluator } from './evaluator';
import { AnnotationFactory } from './annotation';
@ -355,7 +354,9 @@ var PDFDocument = (function PDFDocumentClosure() {
} else {
throw new Error('PDFDocument: Unknown argument type');
}
assert(stream.length > 0, 'stream must have data');
if (stream.length <= 0) {
throw new Error('PDFDocument: stream must have data');
}
this.pdfManager = pdfManager;
this.stream = stream;