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.');