1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 09:38:06 +02:00

Convert the various ...Exceptions to proper classes, to reduce code duplication

By utilizing a base "class", things become significantly simpler. Unfortunately the new `BaseException` cannot be a proper ES6 class and just extend `Error`, since the SystemJS dependency doesn't seem to play well with that.
Note also that we (generally) need to keep the `name` property on the actual `...Exception` object, rather than on its prototype, since the property will otherwise be dropped during the structured cloning used with `postMessage`.
This commit is contained in:
Jonas Jenwald 2019-09-29 01:18:48 +02:00
parent cd909c531f
commit 5d93fda4f2
3 changed files with 44 additions and 120 deletions

View file

@ -14,7 +14,7 @@
*/
/* eslint no-var: error */
import { assert, warn } from '../shared/util';
import { assert, BaseException, warn } from '../shared/util';
function getLookupTableFactory(initializer) {
let lookup;
@ -28,43 +28,17 @@ function getLookupTableFactory(initializer) {
};
}
const MissingDataException = (function MissingDataExceptionClosure() {
function MissingDataException(begin, end) {
class MissingDataException extends BaseException {
constructor(begin, end) {
super(`Missing data [${begin}, ${end})`);
this.begin = begin;
this.end = end;
this.message = `Missing data [${begin}, ${end})`;
}
}
MissingDataException.prototype = new Error();
MissingDataException.prototype.name = 'MissingDataException';
MissingDataException.constructor = MissingDataException;
class XRefEntryException extends BaseException { }
return MissingDataException;
})();
const XRefEntryException = (function XRefEntryExceptionClosure() {
function XRefEntryException(msg) {
this.message = msg;
}
XRefEntryException.prototype = new Error();
XRefEntryException.prototype.name = 'XRefEntryException';
XRefEntryException.constructor = XRefEntryException;
return XRefEntryException;
})();
const XRefParseException = (function XRefParseExceptionClosure() {
function XRefParseException(msg) {
this.message = msg;
}
XRefParseException.prototype = new Error();
XRefParseException.prototype.name = 'XRefParseException';
XRefParseException.constructor = XRefParseException;
return XRefParseException;
})();
class XRefParseException extends BaseException { }
/**
* Get the value of an inheritable property.