Tweak handling of the onlyRefs-option in the BaseLocalCache class

This commit is contained in:
Jonas Jenwald 2021-08-18 12:24:51 +02:00
parent a936509b77
commit 8ee5acd85d

View File

@ -21,7 +21,9 @@ class BaseLocalCache {
if (this.constructor === BaseLocalCache) { if (this.constructor === BaseLocalCache) {
unreachable("Cannot initialize BaseLocalCache."); unreachable("Cannot initialize BaseLocalCache.");
} }
if (!options || !options.onlyRefs) { this._onlyRefs = (options && options.onlyRefs) === true;
if (!this._onlyRefs) {
this._nameRefMap = new Map(); this._nameRefMap = new Map();
this._imageMap = new Map(); this._imageMap = new Map();
} }
@ -29,6 +31,9 @@ class BaseLocalCache {
} }
getByName(name) { getByName(name) {
if (this._onlyRefs) {
unreachable("Should not call `getByName` method.");
}
const ref = this._nameRefMap.get(name); const ref = this._nameRefMap.get(name);
if (ref) { if (ref) {
return this.getByRef(ref); return this.getByRef(ref);
@ -97,10 +102,6 @@ class LocalFunctionCache extends BaseLocalCache {
super({ onlyRefs: true }); super({ onlyRefs: true });
} }
getByName(name) {
unreachable("Should not call `getByName` method.");
}
set(name = null, ref, data) { set(name = null, ref, data) {
if (!ref) { if (!ref) {
throw new Error('LocalFunctionCache.set - expected "ref" argument.'); throw new Error('LocalFunctionCache.set - expected "ref" argument.');