Skip to content

Commit ef1ad67

Browse files
committed
Unify method return values in the ObjectLoader class
Given that all the methods are already asynchronous we can just use `await` more throughout this code, rather than having to explicitly return function-calls and `undefined`. Note also how none of the `ObjectLoader.prototype.load` call-sites use the return value.
1 parent 04400c5 commit ef1ad67

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/core/object_loader.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,18 @@ function addChildren(node, nodesToVisit) {
5454
* entire PDF document object graph to be traversed.
5555
*/
5656
class ObjectLoader {
57+
refSet = null;
58+
5759
constructor(dict, keys, xref) {
5860
this.dict = dict;
5961
this.keys = keys;
6062
this.xref = xref;
61-
this.refSet = null;
6263
}
6364

6465
async load() {
6566
// Don't walk the graph if all the data is already loaded.
6667
if (this.xref.stream.isDataLoaded) {
67-
return undefined;
68+
return;
6869
}
6970

7071
const { keys, dict } = this;
@@ -78,10 +79,12 @@ class ObjectLoader {
7879
nodesToVisit.push(rawValue);
7980
}
8081
}
81-
return this._walk(nodesToVisit);
82+
await this.#walk(nodesToVisit);
83+
84+
this.refSet = null; // Everything is loaded, clear the cache.
8285
}
8386

84-
async _walk(nodesToVisit) {
87+
async #walk(nodesToVisit) {
8588
const nodesToRevisit = [];
8689
const pendingRequests = [];
8790
// DFS walk of the object graph.
@@ -99,11 +102,10 @@ class ObjectLoader {
99102
currentNode = this.xref.fetch(currentNode);
100103
} catch (ex) {
101104
if (!(ex instanceof MissingDataException)) {
102-
warn(`ObjectLoader._walk - requesting all data: "${ex}".`);
103-
this.refSet = null;
105+
warn(`ObjectLoader.#walk - requesting all data: "${ex}".`);
104106

105-
const { manager } = this.xref.stream;
106-
return manager.requestAllChunks();
107+
await this.xref.stream.manager.requestAllChunks();
108+
return;
107109
}
108110
nodesToRevisit.push(currentNode);
109111
pendingRequests.push({ begin: ex.begin, end: ex.end });
@@ -139,11 +141,8 @@ class ObjectLoader {
139141
this.refSet.remove(node);
140142
}
141143
}
142-
return this._walk(nodesToRevisit);
144+
await this.#walk(nodesToRevisit);
143145
}
144-
// Everything is loaded.
145-
this.refSet = null;
146-
return undefined;
147146
}
148147
}
149148

0 commit comments

Comments
 (0)