Covert the ObjectLoader to a "normal" class

This commit is contained in:
Jonas Jenwald 2021-04-13 18:25:42 +02:00
parent 604cd6d600
commit 6a935682fd

View File

@ -17,28 +17,16 @@ import { Dict, isStream, Ref, RefSet } from "./primitives.js";
import { MissingDataException } from "./core_utils.js"; import { MissingDataException } from "./core_utils.js";
import { warn } from "../shared/util.js"; import { warn } from "../shared/util.js";
/** function mayHaveChildren(value) {
* A helper for loading missing data in `Dict` graphs. It traverses the graph
* depth first and queues up any objects that have missing data. Once it has
* has traversed as many objects that are available it attempts to bundle the
* missing data requests and then resume from the nodes that weren't ready.
*
* NOTE: It provides protection from circular references by keeping track of
* loaded references. However, you must be careful not to load any graphs
* that have references to the catalog or other pages since that will cause the
* entire PDF document object graph to be traversed.
*/
const ObjectLoader = (function () {
function mayHaveChildren(value) {
return ( return (
value instanceof Ref || value instanceof Ref ||
value instanceof Dict || value instanceof Dict ||
Array.isArray(value) || Array.isArray(value) ||
isStream(value) isStream(value)
); );
} }
function addChildren(node, nodesToVisit) { function addChildren(node, nodesToVisit) {
if (node instanceof Dict) { if (node instanceof Dict) {
node = node.getRawValues(); node = node.getRawValues();
} else if (isStream(node)) { } else if (isStream(node)) {
@ -51,17 +39,27 @@ const ObjectLoader = (function () {
nodesToVisit.push(rawValue); nodesToVisit.push(rawValue);
} }
} }
} }
// eslint-disable-next-line no-shadow /**
function ObjectLoader(dict, keys, xref) { * A helper for loading missing data in `Dict` graphs. It traverses the graph
* depth first and queues up any objects that have missing data. Once it has
* has traversed as many objects that are available it attempts to bundle the
* missing data requests and then resume from the nodes that weren't ready.
*
* NOTE: It provides protection from circular references by keeping track of
* loaded references. However, you must be careful not to load any graphs
* that have references to the catalog or other pages since that will cause the
* entire PDF document object graph to be traversed.
*/
class ObjectLoader {
constructor(dict, keys, xref) {
this.dict = dict; this.dict = dict;
this.keys = keys; this.keys = keys;
this.xref = xref; this.xref = xref;
this.refSet = null; this.refSet = null;
} }
ObjectLoader.prototype = {
async load() { async load() {
// Don't walk the graph if all the data is already loaded; note that only // Don't walk the graph if all the data is already loaded; note that only
// `ChunkedStream` instances have a `allChunksLoaded` method. // `ChunkedStream` instances have a `allChunksLoaded` method.
@ -84,7 +82,7 @@ const ObjectLoader = (function () {
} }
} }
return this._walk(nodesToVisit); return this._walk(nodesToVisit);
}, }
async _walk(nodesToVisit) { async _walk(nodesToVisit) {
const nodesToRevisit = []; const nodesToRevisit = [];
@ -148,10 +146,7 @@ const ObjectLoader = (function () {
// Everything is loaded. // Everything is loaded.
this.refSet = null; this.refSet = null;
return undefined; return undefined;
}, }
}; }
return ObjectLoader;
})();
export { ObjectLoader }; export { ObjectLoader };