Covert the ObjectLoader
to a "normal" class
This commit is contained in:
parent
604cd6d600
commit
6a935682fd
@ -17,18 +17,6 @@ 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";
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
function mayHaveChildren(value) {
|
||||||
return (
|
return (
|
||||||
value instanceof Ref ||
|
value instanceof Ref ||
|
||||||
@ -53,15 +41,25 @@ const ObjectLoader = (function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user