1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 01:58:06 +02:00

Refactor ObjectLoader to use Dicts correctly, rather than abusing their internal properties

The `ObjectLoader` currently takes an Object as input, despite actually working with `Dict`s internally. This means that at the (two) existing call-sites, we're passing in the "private" `Dict.map` property directly.

Doing this seems like an anti-pattern, and we could (and even should) simply provide the actual `Dict` when creating an `ObjectLoader` instance.
Accessing properties stored in the `Dict` is now done using the intended methods instead, in particular `getRaw` which (as the name suggests) doesn't do any de-referencing, thus maintaining the current functionality of the code.

The only functional change in this patch is that `ObjectLoader.load` will now ignore empty nodes, such that `ObjectLoader._walk` only needs to deal with nodes that are known to contain data. (This lets us skip, among other checks, meaningless `addChildren` function calls.)
This commit is contained in:
Jonas Jenwald 2017-06-13 10:22:11 +02:00
parent f2fc9ee281
commit 3a20fd165f
3 changed files with 20 additions and 23 deletions

View file

@ -186,9 +186,8 @@ var Page = (function PageClosure() {
this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
}
return this.resourcesPromise.then(() => {
var objectLoader = new ObjectLoader(this.resources.map,
keys,
this.xref);
let objectLoader = new ObjectLoader(this.resources, keys, this.xref);
return objectLoader.load();
});
},