Merge pull request #11185 from Snuffleupagus/Exception-classes
Convert the various `...Exception`s to proper classes, to reduce code duplication
This commit is contained in:
commit
06e4eb4714
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
/* eslint no-var: error */
|
/* eslint no-var: error */
|
||||||
|
|
||||||
import { assert, warn } from '../shared/util';
|
import { assert, BaseException, warn } from '../shared/util';
|
||||||
|
|
||||||
function getLookupTableFactory(initializer) {
|
function getLookupTableFactory(initializer) {
|
||||||
let lookup;
|
let lookup;
|
||||||
@ -28,43 +28,17 @@ function getLookupTableFactory(initializer) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const MissingDataException = (function MissingDataExceptionClosure() {
|
class MissingDataException extends BaseException {
|
||||||
function MissingDataException(begin, end) {
|
constructor(begin, end) {
|
||||||
|
super(`Missing data [${begin}, ${end})`);
|
||||||
this.begin = begin;
|
this.begin = begin;
|
||||||
this.end = end;
|
this.end = end;
|
||||||
this.message = `Missing data [${begin}, ${end})`;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MissingDataException.prototype = new Error();
|
class XRefEntryException extends BaseException { }
|
||||||
MissingDataException.prototype.name = 'MissingDataException';
|
|
||||||
MissingDataException.constructor = MissingDataException;
|
|
||||||
|
|
||||||
return MissingDataException;
|
class XRefParseException extends BaseException { }
|
||||||
})();
|
|
||||||
|
|
||||||
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;
|
|
||||||
})();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of an inheritable property.
|
* Get the value of an inheritable property.
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
/* eslint no-var: error */
|
/* eslint no-var: error */
|
||||||
|
|
||||||
import {
|
import {
|
||||||
assert, CMapCompressionType, isString, removeNullCharacters, stringToBytes,
|
assert, BaseException, CMapCompressionType, isString, removeNullCharacters,
|
||||||
unreachable, Util, warn
|
stringToBytes, unreachable, Util, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
|
|
||||||
const DEFAULT_LINK_REL = 'noopener noreferrer nofollow';
|
const DEFAULT_LINK_REL = 'noopener noreferrer nofollow';
|
||||||
@ -307,18 +307,12 @@ class PageViewport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const RenderingCancelledException = (function RenderingCancelledException() {
|
class RenderingCancelledException extends BaseException {
|
||||||
function RenderingCancelledException(msg, type) {
|
constructor(msg, type) {
|
||||||
this.message = msg;
|
super(msg);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
RenderingCancelledException.prototype = new Error();
|
|
||||||
RenderingCancelledException.prototype.name = 'RenderingCancelledException';
|
|
||||||
RenderingCancelledException.constructor = RenderingCancelledException;
|
|
||||||
|
|
||||||
return RenderingCancelledException;
|
|
||||||
})();
|
|
||||||
|
|
||||||
const LinkTarget = {
|
const LinkTarget = {
|
||||||
NONE: 0, // Default value.
|
NONE: 0, // Default value.
|
||||||
|
@ -401,99 +401,54 @@ function shadow(obj, prop, value) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PasswordException = (function PasswordExceptionClosure() {
|
const BaseException = (function BaseExceptionClosure() {
|
||||||
function PasswordException(msg, code) {
|
function BaseException(message) {
|
||||||
this.name = 'PasswordException';
|
if (this.constructor === BaseException) {
|
||||||
this.message = msg;
|
unreachable('Cannot initialize BaseException.');
|
||||||
|
}
|
||||||
|
this.message = message;
|
||||||
|
this.name = this.constructor.name;
|
||||||
|
}
|
||||||
|
BaseException.prototype = new Error();
|
||||||
|
BaseException.constructor = BaseException;
|
||||||
|
|
||||||
|
return BaseException;
|
||||||
|
})();
|
||||||
|
|
||||||
|
class PasswordException extends BaseException {
|
||||||
|
constructor(msg, code) {
|
||||||
|
super(msg);
|
||||||
this.code = code;
|
this.code = code;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PasswordException.prototype = new Error();
|
class UnknownErrorException extends BaseException {
|
||||||
PasswordException.constructor = PasswordException;
|
constructor(msg, details) {
|
||||||
|
super(msg);
|
||||||
return PasswordException;
|
|
||||||
})();
|
|
||||||
|
|
||||||
const UnknownErrorException = (function UnknownErrorExceptionClosure() {
|
|
||||||
function UnknownErrorException(msg, details) {
|
|
||||||
this.name = 'UnknownErrorException';
|
|
||||||
this.message = msg;
|
|
||||||
this.details = details;
|
this.details = details;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UnknownErrorException.prototype = new Error();
|
class InvalidPDFException extends BaseException { }
|
||||||
UnknownErrorException.constructor = UnknownErrorException;
|
|
||||||
|
|
||||||
return UnknownErrorException;
|
class MissingPDFException extends BaseException { }
|
||||||
})();
|
|
||||||
|
|
||||||
const InvalidPDFException = (function InvalidPDFExceptionClosure() {
|
class UnexpectedResponseException extends BaseException {
|
||||||
function InvalidPDFException(msg) {
|
constructor(msg, status) {
|
||||||
this.name = 'InvalidPDFException';
|
super(msg);
|
||||||
this.message = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
InvalidPDFException.prototype = new Error();
|
|
||||||
InvalidPDFException.constructor = InvalidPDFException;
|
|
||||||
|
|
||||||
return InvalidPDFException;
|
|
||||||
})();
|
|
||||||
|
|
||||||
const MissingPDFException = (function MissingPDFExceptionClosure() {
|
|
||||||
function MissingPDFException(msg) {
|
|
||||||
this.name = 'MissingPDFException';
|
|
||||||
this.message = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
MissingPDFException.prototype = new Error();
|
|
||||||
MissingPDFException.constructor = MissingPDFException;
|
|
||||||
|
|
||||||
return MissingPDFException;
|
|
||||||
})();
|
|
||||||
|
|
||||||
const UnexpectedResponseException =
|
|
||||||
(function UnexpectedResponseExceptionClosure() {
|
|
||||||
function UnexpectedResponseException(msg, status) {
|
|
||||||
this.name = 'UnexpectedResponseException';
|
|
||||||
this.message = msg;
|
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
UnexpectedResponseException.prototype = new Error();
|
|
||||||
UnexpectedResponseException.constructor = UnexpectedResponseException;
|
|
||||||
|
|
||||||
return UnexpectedResponseException;
|
|
||||||
})();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error caused during parsing PDF data.
|
* Error caused during parsing PDF data.
|
||||||
*/
|
*/
|
||||||
const FormatError = (function FormatErrorClosure() {
|
class FormatError extends BaseException { }
|
||||||
function FormatError(msg) {
|
|
||||||
this.message = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
FormatError.prototype = new Error();
|
|
||||||
FormatError.prototype.name = 'FormatError';
|
|
||||||
FormatError.constructor = FormatError;
|
|
||||||
|
|
||||||
return FormatError;
|
|
||||||
})();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error used to indicate task cancellation.
|
* Error used to indicate task cancellation.
|
||||||
*/
|
*/
|
||||||
const AbortException = (function AbortExceptionClosure() {
|
class AbortException extends BaseException { }
|
||||||
function AbortException(msg) {
|
|
||||||
this.name = 'AbortException';
|
|
||||||
this.message = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
AbortException.prototype = new Error();
|
|
||||||
AbortException.constructor = AbortException;
|
|
||||||
|
|
||||||
return AbortException;
|
|
||||||
})();
|
|
||||||
|
|
||||||
const NullCharactersRegExp = /\x00/g;
|
const NullCharactersRegExp = /\x00/g;
|
||||||
|
|
||||||
@ -915,6 +870,7 @@ const createObjectURL = (function createObjectURLClosure() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
BaseException,
|
||||||
FONT_IDENTITY_MATRIX,
|
FONT_IDENTITY_MATRIX,
|
||||||
IDENTITY_MATRIX,
|
IDENTITY_MATRIX,
|
||||||
OPS,
|
OPS,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user