Compare commits

..

No commits in common. "0c1ac54f4847d94292d391a7e54ae174d64191bc" and "3cd1b10433575e718b314fa7b7866b1ac9aa85ad" have entirely different histories.

5 changed files with 80 additions and 63 deletions

View File

@ -1164,7 +1164,9 @@ class Annotation {
} }
const objectLoader = new ObjectLoader(resources, keys, resources.xref); const objectLoader = new ObjectLoader(resources, keys, resources.xref);
return objectLoader.load().then(() => resources); return objectLoader.load().then(function () {
return resources;
});
}); });
} }

View File

@ -1475,7 +1475,9 @@ class Catalog {
if (!found) { if (!found) {
throw new FormatError("Kid reference not found in parent's kids."); throw new FormatError("Kid reference not found in parent's kids.");
} }
return Promise.all(kidPromises).then(() => [total, parentRef]); return Promise.all(kidPromises).then(function () {
return [total, parentRef];
});
}); });
} }

View File

@ -546,7 +546,9 @@ class Page {
resources: this.resources, resources: this.resources,
operatorList: opList, operatorList: opList,
}) })
.then(() => opList); .then(function () {
return opList;
});
}); });
// Fetch the page's annotations and add their operator lists to the // Fetch the page's annotations and add their operator lists to the

View File

@ -450,9 +450,9 @@ class WorkerMessageHandler {
}); });
handler.on("GetPageJSActions", function ({ pageIndex }) { handler.on("GetPageJSActions", function ({ pageIndex }) {
return pdfManager return pdfManager.getPage(pageIndex).then(function (page) {
.getPage(pageIndex) return pdfManager.ensure(page, "jsActions");
.then(page => pdfManager.ensure(page, "jsActions")); });
}); });
handler.on("GetOutline", function (data) { handler.on("GetOutline", function (data) {
@ -479,7 +479,9 @@ class WorkerMessageHandler {
}); });
handler.on("GetData", function (data) { handler.on("GetData", function (data) {
return pdfManager.requestLoadedStream().then(stream => stream.bytes); return pdfManager.requestLoadedStream().then(function (stream) {
return stream.bytes;
});
}); });
handler.on("GetAnnotations", function ({ pageIndex, intent }) { handler.on("GetAnnotations", function ({ pageIndex, intent }) {
@ -810,9 +812,9 @@ class WorkerMessageHandler {
}); });
handler.on("GetStructTree", function (data) { handler.on("GetStructTree", function (data) {
return pdfManager return pdfManager.getPage(data.pageIndex).then(function (page) {
.getPage(data.pageIndex) return pdfManager.ensure(page, "getStructTree");
.then(page => pdfManager.ensure(page, "getStructTree")); });
}); });
handler.on("FontFallback", function (data) { handler.on("FontFallback", function (data) {
@ -870,9 +872,9 @@ class WorkerMessageHandler {
return pdfManager.ensureDoc("startXRef"); return pdfManager.ensureDoc("startXRef");
}); });
handler.on("GetAnnotArray", function (data) { handler.on("GetAnnotArray", function (data) {
return pdfManager return pdfManager.getPage(data.pageIndex).then(function (page) {
.getPage(data.pageIndex) return page.annotations.map(a => a.toString());
.then(page => page.annotations.map(a => a.toString())); });
}); });
} }

View File

@ -192,9 +192,9 @@ describe("api", function () {
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true); expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
// This can be somewhat random -- we cannot guarantee perfect // This can be somewhat random -- we cannot guarantee perfect
// 'Terminate' message to the worker before/after setting up pdfManager. // 'Terminate' message to the worker before/after setting up pdfManager.
const destroyed = loadingTask._worker.promise.then(() => const destroyed = loadingTask._worker.promise.then(function () {
loadingTask.destroy() return loadingTask.destroy();
); });
await destroyed; await destroyed;
expect(true).toEqual(true); expect(true).toEqual(true);
@ -861,9 +861,9 @@ describe("api", function () {
expect(!!worker).toEqual(true); expect(!!worker).toEqual(true);
}); });
const destroyPromise = loadingTask.promise.then(() => const destroyPromise = loadingTask.promise.then(function () {
loadingTask.destroy() return loadingTask.destroy();
); });
await destroyPromise; await destroyPromise;
const destroyedWorker = loadingTask._worker; const destroyedWorker = loadingTask._worker;
@ -890,9 +890,9 @@ describe("api", function () {
expect(messageHandlerPort === worker.port).toEqual(true); expect(messageHandlerPort === worker.port).toEqual(true);
}); });
const destroyPromise = loadingTask.promise.then(() => const destroyPromise = loadingTask.promise.then(function () {
loadingTask.destroy() return loadingTask.destroy();
); });
await destroyPromise; await destroyPromise;
expect(worker.destroyed).toEqual(false); expect(worker.destroyed).toEqual(false);
@ -1141,8 +1141,8 @@ describe("api", function () {
buildGetDocumentParams("Pages-tree-refs.pdf") buildGetDocumentParams("Pages-tree-refs.pdf")
); );
const page1 = loadingTask.promise.then(pdfDoc => const page1 = loadingTask.promise.then(function (pdfDoc) {
pdfDoc.getPage(1).then( return pdfDoc.getPage(1).then(
function (pdfPage) { function (pdfPage) {
expect(pdfPage instanceof PDFPageProxy).toEqual(true); expect(pdfPage instanceof PDFPageProxy).toEqual(true);
expect(pdfPage.ref).toEqual({ num: 6, gen: 0 }); expect(pdfPage.ref).toEqual({ num: 6, gen: 0 });
@ -1150,11 +1150,11 @@ describe("api", function () {
function (reason) { function (reason) {
throw new Error("shall not fail for valid page"); throw new Error("shall not fail for valid page");
} }
) );
); });
const page2 = loadingTask.promise.then(pdfDoc => const page2 = loadingTask.promise.then(function (pdfDoc) {
pdfDoc.getPage(2).then( return pdfDoc.getPage(2).then(
function (pdfPage) { function (pdfPage) {
throw new Error("shall fail for invalid page"); throw new Error("shall fail for invalid page");
}, },
@ -1164,8 +1164,8 @@ describe("api", function () {
"Pages tree contains circular reference." "Pages tree contains circular reference."
); );
} }
) );
); });
await Promise.all([page1, page2]); await Promise.all([page1, page2]);
await loadingTask.destroy(); await loadingTask.destroy();
@ -1396,29 +1396,29 @@ describe("api", function () {
it("gets page labels", async function () { it("gets page labels", async function () {
// PageLabels with Roman/Arabic numerals. // PageLabels with Roman/Arabic numerals.
const loadingTask0 = getDocument(buildGetDocumentParams("bug793632.pdf")); const loadingTask0 = getDocument(buildGetDocumentParams("bug793632.pdf"));
const promise0 = loadingTask0.promise.then(pdfDoc => const promise0 = loadingTask0.promise.then(function (pdfDoc) {
pdfDoc.getPageLabels() return pdfDoc.getPageLabels();
); });
// PageLabels with only a label prefix. // PageLabels with only a label prefix.
const loadingTask1 = getDocument(buildGetDocumentParams("issue1453.pdf")); const loadingTask1 = getDocument(buildGetDocumentParams("issue1453.pdf"));
const promise1 = loadingTask1.promise.then(pdfDoc => const promise1 = loadingTask1.promise.then(function (pdfDoc) {
pdfDoc.getPageLabels() return pdfDoc.getPageLabels();
); });
// PageLabels identical to standard page numbering. // PageLabels identical to standard page numbering.
const loadingTask2 = getDocument(buildGetDocumentParams("rotation.pdf")); const loadingTask2 = getDocument(buildGetDocumentParams("rotation.pdf"));
const promise2 = loadingTask2.promise.then(pdfDoc => const promise2 = loadingTask2.promise.then(function (pdfDoc) {
pdfDoc.getPageLabels() return pdfDoc.getPageLabels();
); });
// PageLabels with bad "Prefix" entries. // PageLabels with bad "Prefix" entries.
const loadingTask3 = getDocument( const loadingTask3 = getDocument(
buildGetDocumentParams("bad-PageLabels.pdf") buildGetDocumentParams("bad-PageLabels.pdf")
); );
const promise3 = loadingTask3.promise.then(pdfDoc => const promise3 = loadingTask3.promise.then(function (pdfDoc) {
pdfDoc.getPageLabels() return pdfDoc.getPageLabels();
); });
const pageLabels = await Promise.all([ const pageLabels = await Promise.all([
promise0, promise0,
@ -1512,7 +1512,9 @@ describe("api", function () {
); );
const promise1 = loadingTask1.promise const promise1 = loadingTask1.promise
.then(pdfDoc => pdfDoc.getOpenAction()) .then(function (pdfDoc) {
return pdfDoc.getOpenAction();
})
.then(function (openAction) { .then(function (openAction) {
expect(openAction.dest).toBeUndefined(); expect(openAction.dest).toBeUndefined();
expect(openAction.action).toEqual("Print"); expect(openAction.action).toEqual("Print");
@ -1520,7 +1522,9 @@ describe("api", function () {
return loadingTask1.destroy(); return loadingTask1.destroy();
}); });
const promise2 = loadingTask2.promise const promise2 = loadingTask2.promise
.then(pdfDoc => pdfDoc.getOpenAction()) .then(function (pdfDoc) {
return pdfDoc.getOpenAction();
})
.then(function (openAction) { .then(function (openAction) {
expect(openAction.dest).toBeUndefined(); expect(openAction.dest).toBeUndefined();
expect(openAction.action).toEqual("Print"); expect(openAction.action).toEqual("Print");
@ -2060,25 +2064,25 @@ describe("api", function () {
const loadingTask0 = getDocument( const loadingTask0 = getDocument(
buildGetDocumentParams("issue9972-1.pdf") buildGetDocumentParams("issue9972-1.pdf")
); );
const promise0 = loadingTask0.promise.then(pdfDoc => const promise0 = loadingTask0.promise.then(function (pdfDoc) {
pdfDoc.getPermissions() return pdfDoc.getPermissions();
); });
// Printing not allowed. // Printing not allowed.
const loadingTask1 = getDocument( const loadingTask1 = getDocument(
buildGetDocumentParams("issue9972-2.pdf") buildGetDocumentParams("issue9972-2.pdf")
); );
const promise1 = loadingTask1.promise.then(pdfDoc => const promise1 = loadingTask1.promise.then(function (pdfDoc) {
pdfDoc.getPermissions() return pdfDoc.getPermissions();
); });
// Copying not allowed. // Copying not allowed.
const loadingTask2 = getDocument( const loadingTask2 = getDocument(
buildGetDocumentParams("issue9972-3.pdf") buildGetDocumentParams("issue9972-3.pdf")
); );
const promise2 = loadingTask2.promise.then(pdfDoc => const promise2 = loadingTask2.promise.then(function (pdfDoc) {
pdfDoc.getPermissions() return pdfDoc.getPermissions();
); });
const totalPermissionCount = Object.keys(PermissionFlag).length; const totalPermissionCount = Object.keys(PermissionFlag).length;
const permissions = await Promise.all([promise0, promise1, promise2]); const permissions = await Promise.all([promise0, promise1, promise2]);
@ -3046,7 +3050,9 @@ describe("api", function () {
params.url = url.href; params.url = url.href;
loadingTask = getDocument(params); loadingTask = getDocument(params);
return loadingTask.promise return loadingTask.promise
.then(pdf => pdf.destroy()) .then(function (pdf) {
return pdf.destroy();
})
.then( .then(
function () { function () {
expect(expectSuccess).toEqual(true); expect(expectSuccess).toEqual(true);
@ -3287,9 +3293,10 @@ describe("api", function () {
const filename = "bug766086.pdf"; const filename = "bug766086.pdf";
const defaultLoadingTask = getDocument(buildGetDocumentParams(filename)); const defaultLoadingTask = getDocument(buildGetDocumentParams(filename));
const defaultPromise = defaultLoadingTask.promise.then(async pdfDoc => { const defaultPromise = defaultLoadingTask.promise.then(function (pdfDoc) {
const pdfPage = await pdfDoc.getPage(1); return pdfDoc.getPage(1).then(function (pdfPage) {
return pdfPage.getAnnotations(); return pdfPage.getAnnotations();
});
}); });
const docBaseUrlLoadingTask = getDocument( const docBaseUrlLoadingTask = getDocument(
@ -3298,9 +3305,10 @@ describe("api", function () {
}) })
); );
const docBaseUrlPromise = docBaseUrlLoadingTask.promise.then( const docBaseUrlPromise = docBaseUrlLoadingTask.promise.then(
async pdfDoc => { function (pdfDoc) {
const pdfPage = await pdfDoc.getPage(1); return pdfDoc.getPage(1).then(function (pdfPage) {
return pdfPage.getAnnotations(); return pdfPage.getAnnotations();
});
} }
); );
@ -3310,9 +3318,10 @@ describe("api", function () {
}) })
); );
const invalidDocBaseUrlPromise = const invalidDocBaseUrlPromise =
invalidDocBaseUrlLoadingTask.promise.then(async pdfDoc => { invalidDocBaseUrlLoadingTask.promise.then(function (pdfDoc) {
const pdfPage = await pdfDoc.getPage(1); return pdfDoc.getPage(1).then(function (pdfPage) {
return pdfPage.getAnnotations(); return pdfPage.getAnnotations();
});
}); });
const [ const [