Merge pull request #12192 from Snuffleupagus/misc-AnnotationStorage-improvements

A couple of (small) tweaks of the `AnnotationStorage` (PR 12173 follow-up)
This commit is contained in:
Tim van der Meij 2020-08-11 23:46:13 +02:00 committed by GitHub
commit 57c988853b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -18,7 +18,7 @@
*/ */
class AnnotationStorage { class AnnotationStorage {
constructor() { constructor() {
this._storage = Object.create(null); this._storage = new Map();
} }
/** /**
@ -32,11 +32,11 @@ class AnnotationStorage {
* @returns {Object} * @returns {Object}
*/ */
getOrCreateValue(key, defaultValue) { getOrCreateValue(key, defaultValue) {
if (key in this._storage) { if (this._storage.has(key)) {
return this._storage[key]; return this._storage.get(key);
} }
this._storage[key] = defaultValue; this._storage.set(key, defaultValue);
return defaultValue; return defaultValue;
} }
@ -49,11 +49,18 @@ class AnnotationStorage {
* @param {Object} value * @param {Object} value
*/ */
setValue(key, value) { setValue(key, value) {
this._storage[key] = value; this._storage.set(key, value);
} }
getAll() { getAll() {
return this._storage; if (this._storage.size === 0) {
return null;
}
return Object.fromEntries(this._storage);
}
get size() {
return this._storage.size;
} }
} }

View File

@ -632,14 +632,13 @@ class PDFDocumentProxy {
constructor(pdfInfo, transport) { constructor(pdfInfo, transport) {
this._pdfInfo = pdfInfo; this._pdfInfo = pdfInfo;
this._transport = transport; this._transport = transport;
this._annotationStorage = new AnnotationStorage();
} }
/** /**
* @type {AnnotationStorage} Storage for annotation data in forms. * @type {AnnotationStorage} Storage for annotation data in forms.
*/ */
get annotationStorage() { get annotationStorage() {
return this._annotationStorage; return shadow(this, "annotationStorage", new AnnotationStorage());
} }
/** /**