Skip to content

Commit 1aa95d2

Browse files
Merge pull request #20944 from Snuffleupagus/PDFObjects-resolve-once
Avoid resolving an `objId` more than once in the `PDFObjects` class
2 parents 4900bd8 + e3564de commit 1aa95d2

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

src/display/pdf_objects.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@ const dataObj = () => ({
2828
class PDFObjects {
2929
#objs = new Map();
3030

31-
/**
32-
* Ensures there is an object defined for `objId`.
33-
*
34-
* @param {string} objId
35-
* @returns {Object}
36-
*/
37-
#ensureObj(objId) {
38-
return this.#objs.getOrInsertComputed(objId, dataObj);
39-
}
40-
4131
/**
4232
* If called *without* callback, this returns the data of `objId` but the
4333
* object needs to be resolved. If it isn't, this method throws.
@@ -54,7 +44,7 @@ class PDFObjects {
5444
// If there is a callback, then the get can be async and the object is
5545
// not required to be resolved right now.
5646
if (callback) {
57-
const obj = this.#ensureObj(objId);
47+
const obj = this.#objs.getOrInsertComputed(objId, dataObj);
5848
obj.promise.then(() => callback(obj.data));
5949
return null;
6050
}
@@ -99,7 +89,10 @@ class PDFObjects {
9989
* @param {any} [data]
10090
*/
10191
resolve(objId, data = null) {
102-
const obj = this.#ensureObj(objId);
92+
const obj = this.#objs.getOrInsertComputed(objId, dataObj);
93+
if (obj.data !== INITIAL_DATA) {
94+
throw new Error(`Object already resolved ${objId}.`);
95+
}
10396
obj.data = data;
10497
obj.resolve();
10598
}

0 commit comments

Comments
 (0)