mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-25 16:37:22 +02:00
Change Promise-returning worker message-handler functions to be asynchronous
A number of these functions are old enough that they predate async/await, and making them asynchronous is ever so slightly shorter/simpler.
This commit is contained in:
parent
f0b5fc3b73
commit
d13c28a044
@ -391,23 +391,22 @@ class WorkerMessageHandler {
|
|||||||
.then(pdfManagerReady, onFailure);
|
.then(pdfManagerReady, onFailure);
|
||||||
}
|
}
|
||||||
|
|
||||||
handler.on("GetPage", function ({ pageIndex }) {
|
handler.on("GetPage", async function ({ pageIndex }) {
|
||||||
return pdfManager.getPage(pageIndex).then(function (page) {
|
const page = await pdfManager.getPage(pageIndex);
|
||||||
return Promise.all([
|
|
||||||
pdfManager.ensure(page, "rotate"),
|
const [rotate, ref, userUnit, view] = await Promise.all([
|
||||||
pdfManager.ensure(page, "ref"),
|
pdfManager.ensure(page, "rotate"),
|
||||||
pdfManager.ensure(page, "userUnit"),
|
pdfManager.ensure(page, "ref"),
|
||||||
pdfManager.ensure(page, "view"),
|
pdfManager.ensure(page, "userUnit"),
|
||||||
]).then(function ([rotate, ref, userUnit, view]) {
|
pdfManager.ensure(page, "view"),
|
||||||
return {
|
]);
|
||||||
rotate,
|
return {
|
||||||
ref,
|
rotate,
|
||||||
refStr: ref?.toString() ?? null,
|
ref,
|
||||||
userUnit,
|
refStr: ref?.toString() ?? null,
|
||||||
view,
|
userUnit,
|
||||||
};
|
view,
|
||||||
});
|
};
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetPageIndex", function ({ num, gen }) {
|
handler.on("GetPageIndex", function ({ num, gen }) {
|
||||||
@ -472,10 +471,9 @@ class WorkerMessageHandler {
|
|||||||
return pdfManager.ensureCatalog("jsActions");
|
return pdfManager.ensureCatalog("jsActions");
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetPageJSActions", function ({ pageIndex }) {
|
handler.on("GetPageJSActions", async function ({ pageIndex }) {
|
||||||
return pdfManager
|
const page = await pdfManager.getPage(pageIndex);
|
||||||
.getPage(pageIndex)
|
return pdfManager.ensure(page, "jsActions");
|
||||||
.then(page => pdfManager.ensure(page, "jsActions"));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on(
|
handler.on(
|
||||||
@ -550,25 +548,27 @@ class WorkerMessageHandler {
|
|||||||
return pdfManager.ensureCatalog("markInfo");
|
return pdfManager.ensureCatalog("markInfo");
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetData", function () {
|
handler.on("GetData", async function () {
|
||||||
return pdfManager.requestLoadedStream().then(stream => stream.bytes);
|
const stream = await pdfManager.requestLoadedStream();
|
||||||
|
return stream.bytes;
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetAnnotations", function ({ pageIndex, intent }) {
|
handler.on("GetAnnotations", async function ({ pageIndex, intent }) {
|
||||||
return pdfManager.getPage(pageIndex).then(function (page) {
|
const page = await pdfManager.getPage(pageIndex);
|
||||||
const task = new WorkerTask(`GetAnnotations: page ${pageIndex}`);
|
|
||||||
startWorkerTask(task);
|
|
||||||
|
|
||||||
return page.getAnnotationsData(handler, task, intent).finally(() => {
|
const task = new WorkerTask(`GetAnnotations: page ${pageIndex}`);
|
||||||
finishWorkerTask(task);
|
startWorkerTask(task);
|
||||||
});
|
|
||||||
});
|
try {
|
||||||
|
return await page.getAnnotationsData(handler, task, intent);
|
||||||
|
} finally {
|
||||||
|
finishWorkerTask(task);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetFieldObjects", function () {
|
handler.on("GetFieldObjects", async function () {
|
||||||
return pdfManager
|
const fieldObjects = await pdfManager.ensureDoc("fieldObjects");
|
||||||
.ensureDoc("fieldObjects")
|
return fieldObjects?.allFields || null;
|
||||||
.then(fieldObjects => fieldObjects?.allFields || null);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetSignatures", function () {
|
handler.on("GetSignatures", function () {
|
||||||
@ -975,10 +975,9 @@ class WorkerMessageHandler {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
handler.on("GetStructTree", function ({ pageIndex }) {
|
handler.on("GetStructTree", async function ({ pageIndex }) {
|
||||||
return pdfManager
|
const page = await pdfManager.getPage(pageIndex);
|
||||||
.getPage(pageIndex)
|
return pdfManager.ensure(page, "getStructTree");
|
||||||
.then(page => pdfManager.ensure(page, "getStructTree"));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("FontFallback", function ({ id }) {
|
handler.on("FontFallback", function ({ id }) {
|
||||||
@ -1049,10 +1048,9 @@ class WorkerMessageHandler {
|
|||||||
handler.on("GetStartXRefPos", function () {
|
handler.on("GetStartXRefPos", function () {
|
||||||
return pdfManager.ensureDoc("startXRef");
|
return pdfManager.ensureDoc("startXRef");
|
||||||
});
|
});
|
||||||
handler.on("GetAnnotArray", function ({ pageIndex }) {
|
handler.on("GetAnnotArray", async function ({ pageIndex }) {
|
||||||
return pdfManager
|
const page = await pdfManager.getPage(pageIndex);
|
||||||
.getPage(pageIndex)
|
return page.annotations.map(a => a.toString());
|
||||||
.then(page => page.annotations.map(a => a.toString()));
|
|
||||||
});
|
});
|
||||||
handler.on("GetWorkerCoverage", function () {
|
handler.on("GetWorkerCoverage", function () {
|
||||||
return globalThis.__coverage__ ?? {};
|
return globalThis.__coverage__ ?? {};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user