From b0a1af306da6ef5bf1aa9b567b15c21fcec6fb22 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 15 Mar 2023 12:20:41 +0100 Subject: [PATCH] Simplify initialization of `static` class properties in the worker-thread Now that we no longer depend on the old Babel version in SystemJS we can remove the `static get ...` work-arounds used to define constants, which leads to slightly more compact code. --- src/core/evaluator.js | 12 +++--------- src/core/function.js | 4 +--- src/core/image_utils.js | 13 +++---------- src/core/operator_list.js | 16 +++------------- src/core/pattern.js | 17 ++++------------- src/display/pattern_helper.js | 12 ++---------- 6 files changed, 16 insertions(+), 58 deletions(-) diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 40d12bf74..012521950 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -182,13 +182,9 @@ function incrementCachedImageMaskCount(data) { // Trying to minimize Date.now() usage and check every 100 time. class TimeSlotManager { - static get TIME_SLOT_DURATION_MS() { - return shadow(this, "TIME_SLOT_DURATION_MS", 20); - } + static TIME_SLOT_DURATION_MS = 20; - static get CHECK_TIME_EVERY() { - return shadow(this, "CHECK_TIME_EVERY", 100); - } + static CHECK_TIME_EVERY = 100; constructor() { this.reset(); @@ -4838,9 +4834,7 @@ class EvaluatorPreprocessor { return shadow(this, "opMap", getOPMap()); } - static get MAX_INVALID_PATH_OPS() { - return shadow(this, "MAX_INVALID_PATH_OPS", 10); - } + static MAX_INVALID_PATH_OPS = 10; constructor(stream, xref, stateManager = new StateManager()) { // TODO(mduan): pass array of knownCommands rather than this.opMap diff --git a/src/core/function.js b/src/core/function.js index a9292b88f..c6564f541 100644 --- a/src/core/function.js +++ b/src/core/function.js @@ -513,9 +513,7 @@ function isPDFFunction(v) { } class PostScriptStack { - static get MAX_STACK_SIZE() { - return shadow(this, "MAX_STACK_SIZE", 100); - } + static MAX_STACK_SIZE = 100; constructor(initialStack) { this.stack = initialStack ? Array.from(initialStack) : []; diff --git a/src/core/image_utils.js b/src/core/image_utils.js index 629d62288..47c9ae51f 100644 --- a/src/core/image_utils.js +++ b/src/core/image_utils.js @@ -16,7 +16,6 @@ import { assert, MAX_IMAGE_SIZE_TO_CACHE, - shadow, unreachable, warn, } from "../shared/util.js"; @@ -173,17 +172,11 @@ class RegionalImageCache extends BaseLocalCache { } class GlobalImageCache { - static get NUM_PAGES_THRESHOLD() { - return shadow(this, "NUM_PAGES_THRESHOLD", 2); - } + static NUM_PAGES_THRESHOLD = 2; - static get MIN_IMAGES_TO_CACHE() { - return shadow(this, "MIN_IMAGES_TO_CACHE", 10); - } + static MIN_IMAGES_TO_CACHE = 10; - static get MAX_BYTE_SIZE() { - return shadow(this, "MAX_BYTE_SIZE", 5 * MAX_IMAGE_SIZE_TO_CACHE); - } + static MAX_BYTE_SIZE = 5 * MAX_IMAGE_SIZE_TO_CACHE; constructor() { if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) { diff --git a/src/core/operator_list.js b/src/core/operator_list.js index 7a49091b1..df35a0f8e 100644 --- a/src/core/operator_list.js +++ b/src/core/operator_list.js @@ -13,13 +13,7 @@ * limitations under the License. */ -import { - ImageKind, - OPS, - RenderingIntentFlag, - shadow, - warn, -} from "../shared/util.js"; +import { ImageKind, OPS, RenderingIntentFlag, warn } from "../shared/util.js"; function addState(parentState, pattern, checkFn, iterateFn, processFn) { let state = parentState; @@ -586,14 +580,10 @@ class QueueOptimizer extends NullOptimizer { } class OperatorList { - static get CHUNK_SIZE() { - return shadow(this, "CHUNK_SIZE", 1000); - } + static CHUNK_SIZE = 1000; // Close to chunk size. - static get CHUNK_SIZE_ABOUT() { - return shadow(this, "CHUNK_SIZE_ABOUT", this.CHUNK_SIZE - 5); - } + static CHUNK_SIZE_ABOUT = this.CHUNK_SIZE - 5; constructor(intent = 0, streamSink) { this._streamSink = streamSink; diff --git a/src/core/pattern.js b/src/core/pattern.js index 32471a283..3c49df32c 100644 --- a/src/core/pattern.js +++ b/src/core/pattern.js @@ -17,7 +17,6 @@ import { assert, FormatError, info, - shadow, unreachable, Util, warn, @@ -89,9 +88,7 @@ class Pattern { class BaseShading { // A small number to offset the first/last color stops so we can insert ones // to support extend. Number.MIN_VALUE is too small and breaks the extend. - static get SMALL_NUMBER() { - return shadow(this, "SMALL_NUMBER", 1e-6); - } + static SMALL_NUMBER = 1e-6; constructor() { if (this.constructor === BaseShading) { @@ -374,18 +371,12 @@ const getB = (function getBClosure() { })(); class MeshShading extends BaseShading { - static get MIN_SPLIT_PATCH_CHUNKS_AMOUNT() { - return shadow(this, "MIN_SPLIT_PATCH_CHUNKS_AMOUNT", 3); - } + static MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3; - static get MAX_SPLIT_PATCH_CHUNKS_AMOUNT() { - return shadow(this, "MAX_SPLIT_PATCH_CHUNKS_AMOUNT", 20); - } + static MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20; // Count of triangles per entire mesh bounds. - static get TRIANGLE_DENSITY() { - return shadow(this, "TRIANGLE_DENSITY", 20); - } + static TRIANGLE_DENSITY = 20; constructor( stream, diff --git a/src/display/pattern_helper.js b/src/display/pattern_helper.js index eab5b449f..38f544d29 100644 --- a/src/display/pattern_helper.js +++ b/src/display/pattern_helper.js @@ -13,13 +13,7 @@ * limitations under the License. */ -import { - FormatError, - info, - shadow, - unreachable, - Util, -} from "../shared/util.js"; +import { FormatError, info, unreachable, Util } from "../shared/util.js"; import { getCurrentTransform } from "./display_utils.js"; const PathType = { @@ -462,9 +456,7 @@ const PaintType = { class TilingPattern { // 10in @ 300dpi shall be enough. - static get MAX_PATTERN_SIZE() { - return shadow(this, "MAX_PATTERN_SIZE", 3000); - } + static MAX_PATTERN_SIZE = 3000; constructor(IR, color, ctx, canvasGraphicsFactory, baseTransform) { this.operatorList = IR[2];