1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Remove some now redundant validation in getDocument

Given that we now check/validate all options properly this old code can be simplified.
This commit is contained in:
Jonas Jenwald 2024-06-15 13:10:54 +02:00
parent 831a526c10
commit d6612b3427

View file

@ -229,7 +229,7 @@ const DefaultStandardFontDataFactory =
* already populated with data, or a parameter object.
* @returns {PDFDocumentLoadingTask}
*/
function getDocument(src) {
function getDocument(src = {}) {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
if (typeof src === "string" || src instanceof URL) {
src = { url: src };
@ -237,14 +237,6 @@ function getDocument(src) {
src = { data: src };
}
}
if (typeof src !== "object") {
throw new Error("Invalid parameter in getDocument, need parameter object.");
}
if (!src.url && !src.data && !src.range) {
throw new Error(
"Invalid parameter object: need either .data, .range or .url"
);
}
const task = new PDFDocumentLoadingTask();
const { docId } = task;
@ -423,6 +415,9 @@ function getDocument(src) {
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
throw new Error("Not implemented: createPDFNetworkStream");
}
if (!url) {
throw new Error("getDocument - no `url` parameter provided.");
}
const createPDFNetworkStream = params => {
if (
typeof PDFJSDev !== "undefined" &&