From 8ee5acd85db2a632ffe7062fa2a22cab7e3eebe4 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 18 Aug 2021 12:24:51 +0200 Subject: [PATCH] Tweak handling of the `onlyRefs`-option in the `BaseLocalCache` class --- src/core/image_utils.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/image_utils.js b/src/core/image_utils.js index 1cfdbb83f..b1a7e1d4e 100644 --- a/src/core/image_utils.js +++ b/src/core/image_utils.js @@ -21,7 +21,9 @@ class BaseLocalCache { if (this.constructor === BaseLocalCache) { unreachable("Cannot initialize BaseLocalCache."); } - if (!options || !options.onlyRefs) { + this._onlyRefs = (options && options.onlyRefs) === true; + + if (!this._onlyRefs) { this._nameRefMap = new Map(); this._imageMap = new Map(); } @@ -29,6 +31,9 @@ class BaseLocalCache { } getByName(name) { + if (this._onlyRefs) { + unreachable("Should not call `getByName` method."); + } const ref = this._nameRefMap.get(name); if (ref) { return this.getByRef(ref); @@ -97,10 +102,6 @@ class LocalFunctionCache extends BaseLocalCache { super({ onlyRefs: true }); } - getByName(name) { - unreachable("Should not call `getByName` method."); - } - set(name = null, ref, data) { if (!ref) { throw new Error('LocalFunctionCache.set - expected "ref" argument.');