1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Re-factor the BaseException.name handling, and clean-up some code

Once we're finally able to get rid of SystemJS, which is unfortunately still blocked on [bug 1247687](https://bugzilla.mozilla.org/show_bug.cgi?id=1247687), we might also want to clean-up (or even completely remove) the `BaseException` abstraction and simply extend `Error` directly instead.

At that point we'd need to (explicitly) set the `name` on each class anyway, so this patch is essentially preparing for future clean-up. Furthermore, after the `BaseException` abstraction was added there's been *multiple* issues filed about third-party minification breaking our code since `this.constructor.name` is not guaranteed to always do what you intended.

While hard-coding the strings indeed feels quite unfortunate, it's likely the "best" solution to avoid the problem described above.
This commit is contained in:
Jonas Jenwald 2021-08-09 12:02:49 +02:00
parent 745d5cc819
commit 6167566f1b
8 changed files with 67 additions and 40 deletions

View file

@ -52,17 +52,29 @@ function getArrayLookupTableFactory(initializer) {
class MissingDataException extends BaseException {
constructor(begin, end) {
super(`Missing data [${begin}, ${end})`);
super(`Missing data [${begin}, ${end})`, "MissingDataException");
this.begin = begin;
this.end = end;
}
}
class ParserEOFException extends BaseException {}
class ParserEOFException extends BaseException {
constructor(msg) {
super(msg, "ParserEOFException");
}
}
class XRefEntryException extends BaseException {}
class XRefEntryException extends BaseException {
constructor(msg) {
super(msg, "XRefEntryException");
}
}
class XRefParseException extends BaseException {}
class XRefParseException extends BaseException {
constructor(msg) {
super(msg, "XRefParseException");
}
}
/**
* Get the value of an inheritable property.

View file

@ -20,7 +20,7 @@ import { CCITTFaxDecoder } from "./ccitt.js";
class Jbig2Error extends BaseException {
constructor(msg) {
super(`JBIG2 error: ${msg}`);
super(`JBIG2 error: ${msg}`, "Jbig2Error");
}
}

View file

@ -18,18 +18,22 @@ import { readUint16 } from "./core_utils.js";
class JpegError extends BaseException {
constructor(msg) {
super(`JPEG error: ${msg}`);
super(`JPEG error: ${msg}`, "JpegError");
}
}
class DNLMarkerError extends BaseException {
constructor(message, scanLines) {
super(message);
super(message, "DNLMarkerError");
this.scanLines = scanLines;
}
}
class EOIMarkerError extends BaseException {}
class EOIMarkerError extends BaseException {
constructor(msg) {
super(msg, "EOIMarkerError");
}
}
/**
* This code was forked from https://github.com/notmasteryet/jpgjs.

View file

@ -19,7 +19,7 @@ import { ArithmeticDecoder } from "./arithmetic_decoder.js";
class JpxError extends BaseException {
constructor(msg) {
super(`JPX error: ${msg}`);
super(`JPX error: ${msg}`, "JpxError");
}
}