mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-09 00:25:51 +02:00
Remove unused parameters from worker message-handler functions
A lot of these (often old) handlers don't need any parameters, hence their `data` parameters needlessly increase code-size. Also, for the functions that do need parameters, use parameter destructuring consistently throughout the message-handler functions.
This commit is contained in:
parent
d29293622e
commit
f0b5fc3b73
@ -391,8 +391,8 @@ class WorkerMessageHandler {
|
|||||||
.then(pdfManagerReady, onFailure);
|
.then(pdfManagerReady, onFailure);
|
||||||
}
|
}
|
||||||
|
|
||||||
handler.on("GetPage", function (data) {
|
handler.on("GetPage", function ({ pageIndex }) {
|
||||||
return pdfManager.getPage(data.pageIndex).then(function (page) {
|
return pdfManager.getPage(pageIndex).then(function (page) {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
pdfManager.ensure(page, "rotate"),
|
pdfManager.ensure(page, "rotate"),
|
||||||
pdfManager.ensure(page, "ref"),
|
pdfManager.ensure(page, "ref"),
|
||||||
@ -410,73 +410,65 @@ class WorkerMessageHandler {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetPageIndex", function (data) {
|
handler.on("GetPageIndex", function ({ num, gen }) {
|
||||||
const pageRef = Ref.get(data.num, data.gen);
|
return pdfManager.ensureCatalog("getPageIndex", [Ref.get(num, gen)]);
|
||||||
return pdfManager.ensureCatalog("getPageIndex", [pageRef]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetDestinations", function (data) {
|
handler.on("GetDestinations", function () {
|
||||||
return pdfManager.ensureCatalog("destinations");
|
return pdfManager.ensureCatalog("destinations");
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetDestination", function (data) {
|
handler.on("GetDestination", function ({ id }) {
|
||||||
return pdfManager.ensureCatalog("getDestination", [data.id]);
|
return pdfManager.ensureCatalog("getDestination", [id]);
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetPageLabels", function (data) {
|
handler.on("GetPageLabels", function () {
|
||||||
return pdfManager.ensureCatalog("pageLabels");
|
return pdfManager.ensureCatalog("pageLabels");
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetPageLayout", function (data) {
|
handler.on("GetPageLayout", function () {
|
||||||
return pdfManager.ensureCatalog("pageLayout");
|
return pdfManager.ensureCatalog("pageLayout");
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetPageMode", function (data) {
|
handler.on("GetPageMode", function () {
|
||||||
return pdfManager.ensureCatalog("pageMode");
|
return pdfManager.ensureCatalog("pageMode");
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetViewerPreferences", function (data) {
|
handler.on("GetViewerPreferences", function () {
|
||||||
return pdfManager.ensureCatalog("viewerPreferences");
|
return pdfManager.ensureCatalog("viewerPreferences");
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetOpenAction", function (data) {
|
handler.on("GetOpenAction", function () {
|
||||||
return pdfManager.ensureCatalog("openAction");
|
return pdfManager.ensureCatalog("openAction");
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetAttachments", function (data) {
|
handler.on("GetAttachments", function () {
|
||||||
return pdfManager.ensureCatalog("attachments");
|
return pdfManager.ensureCatalog("attachments");
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on(
|
handler.on("GetAttachmentContent", async function (id) {
|
||||||
"GetAttachmentContent",
|
let passwordEx;
|
||||||
/**
|
|
||||||
* @param {string} id
|
|
||||||
* Unique attachment identifier (required).
|
|
||||||
*/
|
|
||||||
async function (id) {
|
|
||||||
let passwordEx;
|
|
||||||
|
|
||||||
// Loop to prompt again after an incorrect password.
|
// Loop to prompt again after an incorrect password.
|
||||||
while (true) {
|
while (true) {
|
||||||
const password = passwordEx ? await getPassword(passwordEx) : null;
|
const password = passwordEx ? await getPassword(passwordEx) : null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (password) {
|
if (password) {
|
||||||
pdfManager.updatePassword(password);
|
pdfManager.updatePassword(password);
|
||||||
}
|
|
||||||
return await pdfManager.ensureCatalog("attachmentContent", [id]);
|
|
||||||
} catch (ex) {
|
|
||||||
if (ex instanceof PasswordException) {
|
|
||||||
passwordEx = ex;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
throw ex;
|
|
||||||
}
|
}
|
||||||
|
return await pdfManager.ensureCatalog("attachmentContent", [id]);
|
||||||
|
} catch (ex) {
|
||||||
|
if (ex instanceof PasswordException) {
|
||||||
|
passwordEx = ex;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
handler.on("GetDocJSActions", function (data) {
|
handler.on("GetDocJSActions", function () {
|
||||||
return pdfManager.ensureCatalog("jsActions");
|
return pdfManager.ensureCatalog("jsActions");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -534,19 +526,19 @@ class WorkerMessageHandler {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
handler.on("GetOutline", function (data) {
|
handler.on("GetOutline", function () {
|
||||||
return pdfManager.ensureCatalog("documentOutline");
|
return pdfManager.ensureCatalog("documentOutline");
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetOptionalContentConfig", function (data) {
|
handler.on("GetOptionalContentConfig", function () {
|
||||||
return pdfManager.ensureCatalog("optionalContentConfig");
|
return pdfManager.ensureCatalog("optionalContentConfig");
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetPermissions", function (data) {
|
handler.on("GetPermissions", function () {
|
||||||
return pdfManager.ensureCatalog("permissions");
|
return pdfManager.ensureCatalog("permissions");
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetMetadata", function (data) {
|
handler.on("GetMetadata", function () {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
pdfManager.ensureDoc("documentInfo"),
|
pdfManager.ensureDoc("documentInfo"),
|
||||||
pdfManager.ensureCatalog("metadata"),
|
pdfManager.ensureCatalog("metadata"),
|
||||||
@ -554,11 +546,11 @@ class WorkerMessageHandler {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetMarkInfo", function (data) {
|
handler.on("GetMarkInfo", function () {
|
||||||
return pdfManager.ensureCatalog("markInfo");
|
return pdfManager.ensureCatalog("markInfo");
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetData", function (data) {
|
handler.on("GetData", function () {
|
||||||
return pdfManager.requestLoadedStream().then(stream => stream.bytes);
|
return pdfManager.requestLoadedStream().then(stream => stream.bytes);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -573,13 +565,13 @@ class WorkerMessageHandler {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetFieldObjects", function (data) {
|
handler.on("GetFieldObjects", function () {
|
||||||
return pdfManager
|
return pdfManager
|
||||||
.ensureDoc("fieldObjects")
|
.ensureDoc("fieldObjects")
|
||||||
.then(fieldObjects => fieldObjects?.allFields || null);
|
.then(fieldObjects => fieldObjects?.allFields || null);
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetSignatures", function (data) {
|
handler.on("GetSignatures", function () {
|
||||||
return pdfManager.ensureDoc("signatures");
|
return pdfManager.ensureDoc("signatures");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -587,11 +579,11 @@ class WorkerMessageHandler {
|
|||||||
return pdfManager.ensureDoc("getSignatureData", [id]);
|
return pdfManager.ensureDoc("getSignatureData", [id]);
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("HasJSActions", function (data) {
|
handler.on("HasJSActions", function () {
|
||||||
return pdfManager.ensureDoc("hasJSActions");
|
return pdfManager.ensureDoc("hasJSActions");
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("GetCalculationOrderIds", function (data) {
|
handler.on("GetCalculationOrderIds", function () {
|
||||||
return pdfManager.ensureDoc("calculationOrderIds");
|
return pdfManager.ensureDoc("calculationOrderIds");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -893,96 +885,104 @@ class WorkerMessageHandler {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
handler.on("GetOperatorList", function (data, sink) {
|
handler.on(
|
||||||
const { pageId, pageIndex } = data;
|
"GetOperatorList",
|
||||||
pdfManager.getPage(pageId).then(function (page) {
|
function (
|
||||||
const task = new WorkerTask(`GetOperatorList: page ${pageIndex}`);
|
{ pageId, pageIndex, intent, cacheKey, annotationStorage, modifiedIds },
|
||||||
startWorkerTask(task);
|
sink
|
||||||
|
) {
|
||||||
|
pdfManager.getPage(pageId).then(function (page) {
|
||||||
|
const task = new WorkerTask(`GetOperatorList: page ${pageIndex}`);
|
||||||
|
startWorkerTask(task);
|
||||||
|
|
||||||
// NOTE: Keep this condition in sync with the `info` helper function.
|
// NOTE: Keep this condition in sync with the `info` helper function.
|
||||||
const start = verbosity >= VerbosityLevel.INFOS ? Date.now() : 0;
|
const start = verbosity >= VerbosityLevel.INFOS ? Date.now() : 0;
|
||||||
|
|
||||||
// Pre compile the pdf page and fetch the fonts/images.
|
// Pre compile the pdf page and fetch the fonts/images.
|
||||||
page
|
page
|
||||||
.getOperatorList({
|
.getOperatorList({
|
||||||
handler,
|
handler,
|
||||||
sink,
|
sink,
|
||||||
task,
|
task,
|
||||||
intent: data.intent,
|
intent,
|
||||||
cacheKey: data.cacheKey,
|
cacheKey,
|
||||||
annotationStorage: data.annotationStorage,
|
annotationStorage,
|
||||||
modifiedIds: data.modifiedIds,
|
modifiedIds,
|
||||||
pageIndex,
|
pageIndex,
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
opListInfo => {
|
opListInfo => {
|
||||||
if (start) {
|
if (start) {
|
||||||
info(
|
info(
|
||||||
`${task.name}; time=${Date.now() - start}ms, len=${opListInfo.length}`
|
`${task.name}; time=${Date.now() - start}ms, len=${opListInfo.length}`
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
sink.close();
|
||||||
|
},
|
||||||
|
reason => {
|
||||||
|
if (task.terminated) {
|
||||||
|
return; // ignoring errors from the terminated thread
|
||||||
|
}
|
||||||
|
sink.error(reason);
|
||||||
}
|
}
|
||||||
sink.close();
|
)
|
||||||
},
|
.finally(() => {
|
||||||
reason => {
|
finishWorkerTask(task);
|
||||||
if (task.terminated) {
|
});
|
||||||
return; // ignoring errors from the terminated thread
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
handler.on(
|
||||||
|
"GetTextContent",
|
||||||
|
function (
|
||||||
|
{ pageId, pageIndex, includeMarkedContent, disableNormalization },
|
||||||
|
sink
|
||||||
|
) {
|
||||||
|
pdfManager.getPage(pageId).then(function (page) {
|
||||||
|
const task = new WorkerTask("GetTextContent: page " + pageIndex);
|
||||||
|
startWorkerTask(task);
|
||||||
|
|
||||||
|
// NOTE: Keep this condition in sync with the `info` helper function.
|
||||||
|
const start = verbosity >= VerbosityLevel.INFOS ? Date.now() : 0;
|
||||||
|
|
||||||
|
page
|
||||||
|
.extractTextContent({
|
||||||
|
handler,
|
||||||
|
task,
|
||||||
|
sink,
|
||||||
|
includeMarkedContent,
|
||||||
|
disableNormalization,
|
||||||
|
})
|
||||||
|
.then(
|
||||||
|
() => {
|
||||||
|
if (start) {
|
||||||
|
info(`${task.name}; time=${Date.now() - start}ms`);
|
||||||
|
}
|
||||||
|
sink.close();
|
||||||
|
},
|
||||||
|
reason => {
|
||||||
|
if (task.terminated) {
|
||||||
|
return; // ignoring errors from the terminated thread
|
||||||
|
}
|
||||||
|
sink.error(reason);
|
||||||
}
|
}
|
||||||
sink.error(reason);
|
)
|
||||||
}
|
.finally(() => {
|
||||||
)
|
finishWorkerTask(task);
|
||||||
.finally(() => {
|
});
|
||||||
finishWorkerTask(task);
|
});
|
||||||
});
|
}
|
||||||
});
|
);
|
||||||
});
|
|
||||||
|
|
||||||
handler.on("GetTextContent", function (data, sink) {
|
handler.on("GetStructTree", function ({ pageIndex }) {
|
||||||
const { pageId, pageIndex, includeMarkedContent, disableNormalization } =
|
|
||||||
data;
|
|
||||||
|
|
||||||
pdfManager.getPage(pageId).then(function (page) {
|
|
||||||
const task = new WorkerTask("GetTextContent: page " + pageIndex);
|
|
||||||
startWorkerTask(task);
|
|
||||||
|
|
||||||
// NOTE: Keep this condition in sync with the `info` helper function.
|
|
||||||
const start = verbosity >= VerbosityLevel.INFOS ? Date.now() : 0;
|
|
||||||
|
|
||||||
page
|
|
||||||
.extractTextContent({
|
|
||||||
handler,
|
|
||||||
task,
|
|
||||||
sink,
|
|
||||||
includeMarkedContent,
|
|
||||||
disableNormalization,
|
|
||||||
})
|
|
||||||
.then(
|
|
||||||
() => {
|
|
||||||
if (start) {
|
|
||||||
info(`${task.name}; time=${Date.now() - start}ms`);
|
|
||||||
}
|
|
||||||
sink.close();
|
|
||||||
},
|
|
||||||
reason => {
|
|
||||||
if (task.terminated) {
|
|
||||||
return; // ignoring errors from the terminated thread
|
|
||||||
}
|
|
||||||
sink.error(reason);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.finally(() => {
|
|
||||||
finishWorkerTask(task);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
handler.on("GetStructTree", function (data) {
|
|
||||||
return pdfManager
|
return pdfManager
|
||||||
.getPage(data.pageIndex)
|
.getPage(pageIndex)
|
||||||
.then(page => pdfManager.ensure(page, "getStructTree"));
|
.then(page => pdfManager.ensure(page, "getStructTree"));
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("FontFallback", function (data) {
|
handler.on("FontFallback", function ({ id }) {
|
||||||
return pdfManager.fontFallback(data.id, handler);
|
return pdfManager.fontFallback(id, handler);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -1005,11 +1005,11 @@ class WorkerMessageHandler {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handler.on("Cleanup", function (data) {
|
handler.on("Cleanup", function () {
|
||||||
return pdfManager.cleanup(/* manuallyTriggered = */ true);
|
return pdfManager.cleanup(/* manuallyTriggered = */ true);
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("Terminate", async function (data) {
|
handler.on("Terminate", async function () {
|
||||||
terminated = true;
|
terminated = true;
|
||||||
|
|
||||||
const waitOn = [];
|
const waitOn = [];
|
||||||
@ -1037,21 +1037,21 @@ class WorkerMessageHandler {
|
|||||||
handler = null;
|
handler = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.on("Ready", function (data) {
|
handler.on("Ready", function () {
|
||||||
setupDoc(docParams);
|
setupDoc(docParams);
|
||||||
docParams = null; // we don't need docParams anymore -- saving memory.
|
docParams = null; // we don't need docParams anymore -- saving memory.
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||||
handler.on("GetXFADatasets", function (data) {
|
handler.on("GetXFADatasets", function () {
|
||||||
return pdfManager.ensureDoc("xfaDatasets");
|
return pdfManager.ensureDoc("xfaDatasets");
|
||||||
});
|
});
|
||||||
handler.on("GetStartXRefPos", function (data) {
|
handler.on("GetStartXRefPos", function () {
|
||||||
return pdfManager.ensureDoc("startXRef");
|
return pdfManager.ensureDoc("startXRef");
|
||||||
});
|
});
|
||||||
handler.on("GetAnnotArray", function (data) {
|
handler.on("GetAnnotArray", function ({ pageIndex }) {
|
||||||
return pdfManager
|
return pdfManager
|
||||||
.getPage(data.pageIndex)
|
.getPage(pageIndex)
|
||||||
.then(page => page.annotations.map(a => a.toString()));
|
.then(page => page.annotations.map(a => a.toString()));
|
||||||
});
|
});
|
||||||
handler.on("GetWorkerCoverage", function () {
|
handler.on("GetWorkerCoverage", function () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user