1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 14:48:08 +02:00

Merge pull request #18598 from Snuffleupagus/base-class-init-TESTING-check

Limit base-class initialization checks to development and TESTING modes
This commit is contained in:
Tim van der Meij 2024-08-12 19:06:21 +02:00 committed by GitHub
commit d0fbfe10c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 79 additions and 20 deletions

View file

@ -17,7 +17,10 @@ import { bytesToString, shadow, unreachable } from "../shared/util.js";
class BaseStream {
constructor() {
if (this.constructor === BaseStream) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === BaseStream
) {
unreachable("Cannot initialize BaseStream.");
}
}

View file

@ -62,7 +62,10 @@ function resizeRgbImage(src, dest, w1, h1, w2, h2, alpha01) {
class ColorSpace {
constructor(name, numComps) {
if (this.constructor === ColorSpace) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === ColorSpace
) {
unreachable("Cannot initialize ColorSpace.");
}
this.name = name;

View file

@ -693,7 +693,10 @@ class NullCipher {
class AESBaseCipher {
constructor() {
if (this.constructor === AESBaseCipher) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === AESBaseCipher
) {
unreachable("Cannot initialize AESBaseCipher.");
}

View file

@ -769,7 +769,10 @@ class Commands {
class CompiledFont {
constructor(fontMatrix) {
if (this.constructor === CompiledFont) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === CompiledFont
) {
unreachable("Cannot initialize CompiledFont.");
}
this.fontMatrix = fontMatrix;

View file

@ -23,7 +23,10 @@ import { RefSet, RefSetCache } from "./primitives.js";
class BaseLocalCache {
constructor(options) {
if (this.constructor === BaseLocalCache) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === BaseLocalCache
) {
unreachable("Cannot initialize BaseLocalCache.");
}
this._onlyRefs = options?.onlyRefs === true;

View file

@ -23,7 +23,10 @@ import { FormatError, unreachable, warn } from "../shared/util.js";
*/
class NameOrNumberTree {
constructor(root, xref, type) {
if (this.constructor === NameOrNumberTree) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === NameOrNumberTree
) {
unreachable("Cannot initialize NameOrNumberTree.");
}
this.root = root;

View file

@ -98,7 +98,10 @@ class BaseShading {
static SMALL_NUMBER = 1e-6;
constructor() {
if (this.constructor === BaseShading) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === BaseShading
) {
unreachable("Cannot initialize BaseShading.");
}
}

View file

@ -37,7 +37,10 @@ function parseDocBaseUrl(url) {
class BasePdfManager {
constructor(args) {
if (this.constructor === BasePdfManager) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === BasePdfManager
) {
unreachable("Cannot initialize BasePdfManager.");
}
this._docBaseUrl = parseDocBaseUrl(args.docBaseUrl);

View file

@ -17,7 +17,10 @@ import { CMapCompressionType, unreachable } from "../shared/util.js";
class BaseFilterFactory {
constructor() {
if (this.constructor === BaseFilterFactory) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === BaseFilterFactory
) {
unreachable("Cannot initialize BaseFilterFactory.");
}
}
@ -49,7 +52,10 @@ class BaseCanvasFactory {
#enableHWA = false;
constructor({ enableHWA = false } = {}) {
if (this.constructor === BaseCanvasFactory) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === BaseCanvasFactory
) {
unreachable("Cannot initialize BaseCanvasFactory.");
}
this.#enableHWA = enableHWA;
@ -101,7 +107,10 @@ class BaseCanvasFactory {
class BaseCMapReaderFactory {
constructor({ baseUrl = null, isCompressed = true }) {
if (this.constructor === BaseCMapReaderFactory) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === BaseCMapReaderFactory
) {
unreachable("Cannot initialize BaseCMapReaderFactory.");
}
this.baseUrl = baseUrl;
@ -139,7 +148,10 @@ class BaseCMapReaderFactory {
class BaseStandardFontDataFactory {
constructor({ baseUrl = null }) {
if (this.constructor === BaseStandardFontDataFactory) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === BaseStandardFontDataFactory
) {
unreachable("Cannot initialize BaseStandardFontDataFactory.");
}
this.baseUrl = baseUrl;
@ -171,7 +183,10 @@ class BaseStandardFontDataFactory {
class BaseSVGFactory {
constructor() {
if (this.constructor === BaseSVGFactory) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === BaseSVGFactory
) {
unreachable("Cannot initialize BaseSVGFactory.");
}
}

View file

@ -140,7 +140,10 @@ class AnnotationEditor {
* @param {AnnotationEditorParameters} parameters
*/
constructor(parameters) {
if (this.constructor === AnnotationEditor) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === AnnotationEditor
) {
unreachable("Cannot initialize AnnotationEditor.");
}

View file

@ -35,7 +35,10 @@ function applyBoundingBox(ctx, bbox) {
class BaseShadingPattern {
constructor() {
if (this.constructor === BaseShadingPattern) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === BaseShadingPattern
) {
unreachable("Cannot initialize BaseShadingPattern.");
}
}

View file

@ -468,7 +468,10 @@ function shadow(obj, prop, value, nonSerializable = false) {
const BaseException = (function BaseExceptionClosure() {
// eslint-disable-next-line no-shadow
function BaseException(message, name) {
if (this.constructor === BaseException) {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === BaseException
) {
unreachable("Cannot initialize BaseException.");
}
this.message = message;

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.");
}