Merge pull request #11390 from Snuffleupagus/checkFirstPage-await-cleanup

Ensure that `PDFDocument.checkFirstPage` waits for cleanup to complete (PR 10392 follow-up)
This commit is contained in:
Tim van der Meij 2019-12-08 20:13:00 +01:00 committed by GitHub
commit 07212bf5f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 5 deletions

View File

@ -664,13 +664,13 @@ class PDFDocument {
}
checkFirstPage() {
return this.getPage(0).catch((reason) => {
return this.getPage(0).catch(async (reason) => {
if (reason instanceof XRefEntryException) {
// Clear out the various caches to ensure that we haven't stored any
// inconsistent and/or incorrect state, since that could easily break
// subsequent `this.getPage` calls.
this._pagePromises.length = 0;
this.cleanup();
await this.cleanup();
throw new XRefParseException();
}

View File

@ -671,9 +671,8 @@ class Catalog {
});
return Promise.all(promises).then((translatedFonts) => {
for (let i = 0, ii = translatedFonts.length; i < ii; i++) {
const font = translatedFonts[i].dict;
delete font.translated;
for (const { dict, } of translatedFonts) {
delete dict.translated;
}
this.fontCache.clear();
this.builtInCMapCache.clear();