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

@ -15,8 +15,8 @@
/* eslint no-var: error */
import {
assert, CMapCompressionType, isString, removeNullCharacters, stringToBytes,
unreachable, Util, warn
assert, BaseException, CMapCompressionType, isString, removeNullCharacters,
stringToBytes, unreachable, Util, warn
} from '../shared/util';
const DEFAULT_LINK_REL = 'noopener noreferrer nofollow';
@ -307,18 +307,12 @@ class PageViewport {
}
}
const RenderingCancelledException = (function RenderingCancelledException() {
function RenderingCancelledException(msg, type) {
this.message = msg;
class RenderingCancelledException extends BaseException {
constructor(msg, type) {
super(msg);
this.type = type;
}
RenderingCancelledException.prototype = new Error();
RenderingCancelledException.prototype.name = 'RenderingCancelledException';
RenderingCancelledException.constructor = RenderingCancelledException;
return RenderingCancelledException;
})();
}
const LinkTarget = {
NONE: 0, // Default value.