diff options
Diffstat (limited to 'src/data/cacheable-object.js')
-rw-r--r-- | src/data/cacheable-object.js | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/data/cacheable-object.js b/src/data/cacheable-object.js index 4b354ef7..651a61cf 100644 --- a/src/data/cacheable-object.js +++ b/src/data/cacheable-object.js @@ -14,7 +14,7 @@ export default class CacheableObject { static cacheValid = Symbol.for('CacheableObject.cacheValid'); static updateValue = Symbol.for('CacheableObject.updateValues'); - constructor() { + constructor({seal = true} = {}) { this[CacheableObject.updateValue] = Object.create(null); this[CacheableObject.cachedValue] = Object.create(null); this[CacheableObject.cacheValid] = Object.create(null); @@ -34,10 +34,14 @@ export default class CacheableObject { this[property] = null; } } + + if (seal) { + Object.seal(this); + } } static finalizeCacheableObjectPrototype() { - if (this[CacheableObject.constructorFinalized]) { + if (Object.hasOwn(this, CacheableObject.constructorFinalized)) { throw new Error(`Constructor ${this.name} already finalized`); } @@ -239,13 +243,13 @@ export class CacheableObjectPropertyValueError extends Error { try { inspectOldValue = inspect(oldValue); - } catch (error) { + } catch { inspectOldValue = colors.red(`(couldn't inspect)`); } try { inspectNewValue = inspect(newValue); - } catch (error) { + } catch { inspectNewValue = colors.red(`(couldn't inspect)`); } |