diff --git a/src/core/object_loader.js b/src/core/object_loader.js index 6f75e4561..28763b25a 100644 --- a/src/core/object_loader.js +++ b/src/core/object_loader.js @@ -54,17 +54,18 @@ function addChildren(node, nodesToVisit) { * entire PDF document object graph to be traversed. */ class ObjectLoader { + refSet = null; + constructor(dict, keys, xref) { this.dict = dict; this.keys = keys; this.xref = xref; - this.refSet = null; } async load() { // Don't walk the graph if all the data is already loaded. if (this.xref.stream.isDataLoaded) { - return undefined; + return; } const { keys, dict } = this; @@ -78,10 +79,12 @@ class ObjectLoader { nodesToVisit.push(rawValue); } } - return this._walk(nodesToVisit); + await this.#walk(nodesToVisit); + + this.refSet = null; // Everything is loaded, clear the cache. } - async _walk(nodesToVisit) { + async #walk(nodesToVisit) { const nodesToRevisit = []; const pendingRequests = []; // DFS walk of the object graph. @@ -99,11 +102,10 @@ class ObjectLoader { currentNode = this.xref.fetch(currentNode); } catch (ex) { if (!(ex instanceof MissingDataException)) { - warn(`ObjectLoader._walk - requesting all data: "${ex}".`); - this.refSet = null; + warn(`ObjectLoader.#walk - requesting all data: "${ex}".`); - const { manager } = this.xref.stream; - return manager.requestAllChunks(); + await this.xref.stream.manager.requestAllChunks(); + return; } nodesToRevisit.push(currentNode); pendingRequests.push({ begin: ex.begin, end: ex.end }); @@ -139,11 +141,8 @@ class ObjectLoader { this.refSet.remove(node); } } - return this._walk(nodesToRevisit); + await this.#walk(nodesToRevisit); } - // Everything is loaded. - this.refSet = null; - return undefined; } }