1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Limit base-class initialization checks to development and TESTING modes

We have a number of base-classes that are only intended to be extended, but never to be used directly. To help enforce this during development these base-class constructors will check for direct usage, however that code is obviously not needed in the actual builds.

*Note:* This patch reduces the size of the `gulp mozcentral` output by `~2.7` kilo-bytes, which isn't a lot but still cannot hurt.
This commit is contained in:
Jonas Jenwald 2024-08-12 11:59:13 +02:00
parent aa2337f934
commit aebb8534f3
16 changed files with 79 additions and 20 deletions

View file

@ -583,7 +583,9 @@ class AppOptions {
}
constructor() {
throw new Error("Cannot initialize AppOptions.");
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
throw new Error("Cannot initialize AppOptions.");
}
}
static get(name) {

View file

@ -20,7 +20,10 @@ const TREEITEM_SELECTED_CLASS = "selected";
class BaseTreeViewer {
constructor(options) {
if (this.constructor === BaseTreeViewer) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === BaseTreeViewer
) {
throw new Error("Cannot initialize BaseTreeViewer.");
}
this.container = options.container;

View file

@ -17,7 +17,10 @@
class BaseExternalServices {
constructor() {
if (this.constructor === BaseExternalServices) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === BaseExternalServices
) {
throw new Error("Cannot initialize BaseExternalServices.");
}
}

View file

@ -30,7 +30,10 @@ class BasePreferences {
#initializedPromise = null;
constructor() {
if (this.constructor === BasePreferences) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === BasePreferences
) {
throw new Error("Cannot initialize BasePreferences.");
}