From e3bde56311b3ae2392feea9b3f3ff421352c1636 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 31 May 2021 12:13:20 +0200 Subject: [PATCH 1/2] Ensure that the old/new `options` are correctly combined in `PartialEvaluator.clone` --- src/core/evaluator.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 79591b4ac..51c0c511c 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -229,9 +229,13 @@ class PartialEvaluator { return shadow(this, "_pdfFunctionFactory", pdfFunctionFactory); } - clone(newOptions = DefaultPartialEvaluatorOptions) { + clone(newOptions = null) { const newEvaluator = Object.create(this); - newEvaluator.options = newOptions; + newEvaluator.options = Object.assign( + Object.create(null), + this.options, + newOptions + ); return newEvaluator; } @@ -3948,9 +3952,7 @@ class TranslatedFont { // When parsing Type3 glyphs, always ignore them if there are errors. // Compared to the parsing of e.g. an entire page, it doesn't really // make sense to only be able to render a Type3 glyph partially. - const type3Options = Object.create(evaluator.options); - type3Options.ignoreErrors = false; - const type3Evaluator = evaluator.clone(type3Options); + const type3Evaluator = evaluator.clone({ ignoreErrors: false }); type3Evaluator.parsingType3Font = true; const translatedFont = this.font, From af78ba64bd139718d77f1f3d6855e869472ddabf Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 31 May 2021 11:54:33 +0200 Subject: [PATCH 2/2] Don't change options of the globally used `PartialEvaluator` in the "should render checkbox with fallback font for printing" unit-test Given that the same `PartialEvaluator`-instance is used for a lot of these unit-tests, manually changing the options in any one test-case could lead to intermittently failing unit-tests since they're run in a random order. To fix this, we simply have to use the existing method to clone the `PartialEvaluator`-instance but with the custom options. --- test/unit/annotation_spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/annotation_spec.js b/test/unit/annotation_spec.js index 7d8b50b45..ec88f8b65 100644 --- a/test/unit/annotation_spec.js +++ b/test/unit/annotation_spec.js @@ -2281,7 +2281,7 @@ describe("annotation", function () { { ref: buttonWidgetRef, data: buttonWidgetDict }, ]); const task = new WorkerTask("test print"); - partialEvaluator.options = { ignoreErrors: true }; + const checkboxEvaluator = partialEvaluator.clone({ ignoreErrors: true }); const annotation = await AnnotationFactory.create( xref, @@ -2293,7 +2293,7 @@ describe("annotation", function () { annotationStorage.set(annotation.data.id, { value: true }); const operatorList = await annotation.getOperatorList( - partialEvaluator, + checkboxEvaluator, task, false, annotationStorage