mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +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:
parent
aa2337f934
commit
aebb8534f3
16 changed files with 79 additions and 20 deletions
|
@ -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.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue