mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-07 17:05:38 +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 {
|
class BaseStream {
|
||||||
constructor() {
|
constructor() {
|
||||||
if (this.constructor === BaseStream) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === BaseStream
|
||||||
|
) {
|
||||||
unreachable("Cannot initialize BaseStream.");
|
unreachable("Cannot initialize BaseStream.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,10 @@ function resizeRgbImage(src, dest, w1, h1, w2, h2, alpha01) {
|
||||||
|
|
||||||
class ColorSpace {
|
class ColorSpace {
|
||||||
constructor(name, numComps) {
|
constructor(name, numComps) {
|
||||||
if (this.constructor === ColorSpace) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === ColorSpace
|
||||||
|
) {
|
||||||
unreachable("Cannot initialize ColorSpace.");
|
unreachable("Cannot initialize ColorSpace.");
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
|
@ -693,7 +693,10 @@ class NullCipher {
|
||||||
|
|
||||||
class AESBaseCipher {
|
class AESBaseCipher {
|
||||||
constructor() {
|
constructor() {
|
||||||
if (this.constructor === AESBaseCipher) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === AESBaseCipher
|
||||||
|
) {
|
||||||
unreachable("Cannot initialize AESBaseCipher.");
|
unreachable("Cannot initialize AESBaseCipher.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -769,7 +769,10 @@ class Commands {
|
||||||
|
|
||||||
class CompiledFont {
|
class CompiledFont {
|
||||||
constructor(fontMatrix) {
|
constructor(fontMatrix) {
|
||||||
if (this.constructor === CompiledFont) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === CompiledFont
|
||||||
|
) {
|
||||||
unreachable("Cannot initialize CompiledFont.");
|
unreachable("Cannot initialize CompiledFont.");
|
||||||
}
|
}
|
||||||
this.fontMatrix = fontMatrix;
|
this.fontMatrix = fontMatrix;
|
||||||
|
|
|
@ -23,7 +23,10 @@ import { RefSet, RefSetCache } from "./primitives.js";
|
||||||
|
|
||||||
class BaseLocalCache {
|
class BaseLocalCache {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
if (this.constructor === BaseLocalCache) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === BaseLocalCache
|
||||||
|
) {
|
||||||
unreachable("Cannot initialize BaseLocalCache.");
|
unreachable("Cannot initialize BaseLocalCache.");
|
||||||
}
|
}
|
||||||
this._onlyRefs = options?.onlyRefs === true;
|
this._onlyRefs = options?.onlyRefs === true;
|
||||||
|
|
|
@ -23,7 +23,10 @@ import { FormatError, unreachable, warn } from "../shared/util.js";
|
||||||
*/
|
*/
|
||||||
class NameOrNumberTree {
|
class NameOrNumberTree {
|
||||||
constructor(root, xref, type) {
|
constructor(root, xref, type) {
|
||||||
if (this.constructor === NameOrNumberTree) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === NameOrNumberTree
|
||||||
|
) {
|
||||||
unreachable("Cannot initialize NameOrNumberTree.");
|
unreachable("Cannot initialize NameOrNumberTree.");
|
||||||
}
|
}
|
||||||
this.root = root;
|
this.root = root;
|
||||||
|
|
|
@ -98,7 +98,10 @@ class BaseShading {
|
||||||
static SMALL_NUMBER = 1e-6;
|
static SMALL_NUMBER = 1e-6;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
if (this.constructor === BaseShading) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === BaseShading
|
||||||
|
) {
|
||||||
unreachable("Cannot initialize BaseShading.");
|
unreachable("Cannot initialize BaseShading.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,10 @@ function parseDocBaseUrl(url) {
|
||||||
|
|
||||||
class BasePdfManager {
|
class BasePdfManager {
|
||||||
constructor(args) {
|
constructor(args) {
|
||||||
if (this.constructor === BasePdfManager) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === BasePdfManager
|
||||||
|
) {
|
||||||
unreachable("Cannot initialize BasePdfManager.");
|
unreachable("Cannot initialize BasePdfManager.");
|
||||||
}
|
}
|
||||||
this._docBaseUrl = parseDocBaseUrl(args.docBaseUrl);
|
this._docBaseUrl = parseDocBaseUrl(args.docBaseUrl);
|
||||||
|
|
|
@ -17,7 +17,10 @@ import { CMapCompressionType, unreachable } from "../shared/util.js";
|
||||||
|
|
||||||
class BaseFilterFactory {
|
class BaseFilterFactory {
|
||||||
constructor() {
|
constructor() {
|
||||||
if (this.constructor === BaseFilterFactory) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === BaseFilterFactory
|
||||||
|
) {
|
||||||
unreachable("Cannot initialize BaseFilterFactory.");
|
unreachable("Cannot initialize BaseFilterFactory.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +52,10 @@ class BaseCanvasFactory {
|
||||||
#enableHWA = false;
|
#enableHWA = false;
|
||||||
|
|
||||||
constructor({ enableHWA = false } = {}) {
|
constructor({ enableHWA = false } = {}) {
|
||||||
if (this.constructor === BaseCanvasFactory) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === BaseCanvasFactory
|
||||||
|
) {
|
||||||
unreachable("Cannot initialize BaseCanvasFactory.");
|
unreachable("Cannot initialize BaseCanvasFactory.");
|
||||||
}
|
}
|
||||||
this.#enableHWA = enableHWA;
|
this.#enableHWA = enableHWA;
|
||||||
|
@ -101,7 +107,10 @@ class BaseCanvasFactory {
|
||||||
|
|
||||||
class BaseCMapReaderFactory {
|
class BaseCMapReaderFactory {
|
||||||
constructor({ baseUrl = null, isCompressed = true }) {
|
constructor({ baseUrl = null, isCompressed = true }) {
|
||||||
if (this.constructor === BaseCMapReaderFactory) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === BaseCMapReaderFactory
|
||||||
|
) {
|
||||||
unreachable("Cannot initialize BaseCMapReaderFactory.");
|
unreachable("Cannot initialize BaseCMapReaderFactory.");
|
||||||
}
|
}
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
|
@ -139,7 +148,10 @@ class BaseCMapReaderFactory {
|
||||||
|
|
||||||
class BaseStandardFontDataFactory {
|
class BaseStandardFontDataFactory {
|
||||||
constructor({ baseUrl = null }) {
|
constructor({ baseUrl = null }) {
|
||||||
if (this.constructor === BaseStandardFontDataFactory) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === BaseStandardFontDataFactory
|
||||||
|
) {
|
||||||
unreachable("Cannot initialize BaseStandardFontDataFactory.");
|
unreachable("Cannot initialize BaseStandardFontDataFactory.");
|
||||||
}
|
}
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
|
@ -171,7 +183,10 @@ class BaseStandardFontDataFactory {
|
||||||
|
|
||||||
class BaseSVGFactory {
|
class BaseSVGFactory {
|
||||||
constructor() {
|
constructor() {
|
||||||
if (this.constructor === BaseSVGFactory) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === BaseSVGFactory
|
||||||
|
) {
|
||||||
unreachable("Cannot initialize BaseSVGFactory.");
|
unreachable("Cannot initialize BaseSVGFactory.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,10 @@ class AnnotationEditor {
|
||||||
* @param {AnnotationEditorParameters} parameters
|
* @param {AnnotationEditorParameters} parameters
|
||||||
*/
|
*/
|
||||||
constructor(parameters) {
|
constructor(parameters) {
|
||||||
if (this.constructor === AnnotationEditor) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === AnnotationEditor
|
||||||
|
) {
|
||||||
unreachable("Cannot initialize AnnotationEditor.");
|
unreachable("Cannot initialize AnnotationEditor.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,10 @@ function applyBoundingBox(ctx, bbox) {
|
||||||
|
|
||||||
class BaseShadingPattern {
|
class BaseShadingPattern {
|
||||||
constructor() {
|
constructor() {
|
||||||
if (this.constructor === BaseShadingPattern) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === BaseShadingPattern
|
||||||
|
) {
|
||||||
unreachable("Cannot initialize BaseShadingPattern.");
|
unreachable("Cannot initialize BaseShadingPattern.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -468,7 +468,10 @@ function shadow(obj, prop, value, nonSerializable = false) {
|
||||||
const BaseException = (function BaseExceptionClosure() {
|
const BaseException = (function BaseExceptionClosure() {
|
||||||
// eslint-disable-next-line no-shadow
|
// eslint-disable-next-line no-shadow
|
||||||
function BaseException(message, name) {
|
function BaseException(message, name) {
|
||||||
if (this.constructor === BaseException) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === BaseException
|
||||||
|
) {
|
||||||
unreachable("Cannot initialize BaseException.");
|
unreachable("Cannot initialize BaseException.");
|
||||||
}
|
}
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
|
|
@ -583,7 +583,9 @@ class AppOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
throw new Error("Cannot initialize AppOptions.");
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||||
|
throw new Error("Cannot initialize AppOptions.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static get(name) {
|
static get(name) {
|
||||||
|
|
|
@ -20,7 +20,10 @@ const TREEITEM_SELECTED_CLASS = "selected";
|
||||||
|
|
||||||
class BaseTreeViewer {
|
class BaseTreeViewer {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
if (this.constructor === BaseTreeViewer) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === BaseTreeViewer
|
||||||
|
) {
|
||||||
throw new Error("Cannot initialize BaseTreeViewer.");
|
throw new Error("Cannot initialize BaseTreeViewer.");
|
||||||
}
|
}
|
||||||
this.container = options.container;
|
this.container = options.container;
|
||||||
|
|
|
@ -17,7 +17,10 @@
|
||||||
|
|
||||||
class BaseExternalServices {
|
class BaseExternalServices {
|
||||||
constructor() {
|
constructor() {
|
||||||
if (this.constructor === BaseExternalServices) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === BaseExternalServices
|
||||||
|
) {
|
||||||
throw new Error("Cannot initialize BaseExternalServices.");
|
throw new Error("Cannot initialize BaseExternalServices.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,10 @@ class BasePreferences {
|
||||||
#initializedPromise = null;
|
#initializedPromise = null;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
if (this.constructor === BasePreferences) {
|
if (
|
||||||
|
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||||
|
this.constructor === BasePreferences
|
||||||
|
) {
|
||||||
throw new Error("Cannot initialize BasePreferences.");
|
throw new Error("Cannot initialize BasePreferences.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue