From cfaf23dee2511f3288c988a6b0314f0fa68d8995 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 22 Jan 2021 12:25:05 +0100 Subject: [PATCH 1/2] Simplify the `PDFFunctionFactory._localFunctionCache` initialization (PR 12034 follow-up) By changing this a `shadow`ed getter, we can simply access it directly and not worry about it being initialized. I have no idea why I didn't just implement it this way in the first place. --- src/core/function.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/core/function.js b/src/core/function.js index 7f2b8d1da..4dcee828e 100644 --- a/src/core/function.js +++ b/src/core/function.js @@ -20,6 +20,7 @@ import { info, isBool, IsEvalSupportedCached, + shadow, unreachable, } from "../shared/util.js"; import { PostScriptLexer, PostScriptParser } from "./ps_parser.js"; @@ -29,7 +30,6 @@ class PDFFunctionFactory { constructor({ xref, isEvalSupported = true }) { this.xref = xref; this.isEvalSupported = isEvalSupported !== false; - this._localFunctionCache = null; // Initialized lazily. } create(fn) { @@ -76,9 +76,6 @@ class PDFFunctionFactory { fnRef = cacheKey.dict && cacheKey.dict.objId; } if (fnRef) { - if (!this._localFunctionCache) { - this._localFunctionCache = new LocalFunctionCache(); - } const localFunction = this._localFunctionCache.getByRef(fnRef); if (localFunction) { return localFunction; @@ -105,12 +102,16 @@ class PDFFunctionFactory { fnRef = cacheKey.dict && cacheKey.dict.objId; } if (fnRef) { - if (!this._localFunctionCache) { - this._localFunctionCache = new LocalFunctionCache(); - } this._localFunctionCache.set(/* name = */ null, fnRef, parsedFunction); } } + + /** + * @private + */ + get _localFunctionCache() { + return shadow(this, "_localFunctionCache", new LocalFunctionCache()); + } } function toNumberArray(arr) { From 8137c0547d89e23ed05c62f79fae67ccacc9878b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 22 Jan 2021 12:27:38 +0100 Subject: [PATCH 2/2] Fix the `gStateObj` lookup in `TranslatedFont._removeType3ColorOperators` (PR 12718 follow-up) As can be seen in https://github.com/mozilla/pdf.js/blob/2cba29036180b420778bd2c91d21d71bd207c146/src/core/evaluator.js#L986 the `gStateObj` (which is actually an Array despite its name), is wrapped in Array when it's inserted into the OperatorList. Hence we obviously need to take this into account when accessing it in `TranslatedFont._removeType3ColorOperators`; this mistake happened because we don't have any test-cases for this particular code-path as far as I know. --- src/core/evaluator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/evaluator.js b/src/core/evaluator.js index fb0c075ae..df604292b 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -3683,7 +3683,7 @@ class TranslatedFont { continue; case OPS.setGState: - const gStateObj = operatorList.argsArray[i]; + const [gStateObj] = operatorList.argsArray[i]; let j = 0, jj = gStateObj.length; while (j < jj) {