Skip to content

Commit 57c9888

Browse files
Merge pull request #12192 from Snuffleupagus/misc-AnnotationStorage-improvements
A couple of (small) tweaks of the `AnnotationStorage` (PR 12173 follow-up)
2 parents 7fb01f9 + 4d351ea commit 57c9888

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/display/annotation_storage.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class AnnotationStorage {
2020
constructor() {
21-
this._storage = Object.create(null);
21+
this._storage = new Map();
2222
}
2323

2424
/**
@@ -32,11 +32,11 @@ class AnnotationStorage {
3232
* @returns {Object}
3333
*/
3434
getOrCreateValue(key, defaultValue) {
35-
if (key in this._storage) {
36-
return this._storage[key];
35+
if (this._storage.has(key)) {
36+
return this._storage.get(key);
3737
}
3838

39-
this._storage[key] = defaultValue;
39+
this._storage.set(key, defaultValue);
4040
return defaultValue;
4141
}
4242

@@ -49,11 +49,18 @@ class AnnotationStorage {
4949
* @param {Object} value
5050
*/
5151
setValue(key, value) {
52-
this._storage[key] = value;
52+
this._storage.set(key, value);
5353
}
5454

5555
getAll() {
56-
return this._storage;
56+
if (this._storage.size === 0) {
57+
return null;
58+
}
59+
return Object.fromEntries(this._storage);
60+
}
61+
62+
get size() {
63+
return this._storage.size;
5764
}
5865
}
5966

src/display/api.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -632,14 +632,13 @@ class PDFDocumentProxy {
632632
constructor(pdfInfo, transport) {
633633
this._pdfInfo = pdfInfo;
634634
this._transport = transport;
635-
this._annotationStorage = new AnnotationStorage();
636635
}
637636

638637
/**
639638
* @type {AnnotationStorage} Storage for annotation data in forms.
640639
*/
641640
get annotationStorage() {
642-
return this._annotationStorage;
641+
return shadow(this, "annotationStorage", new AnnotationStorage());
643642
}
644643

645644
/**

0 commit comments

Comments
 (0)