mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Use shorter arrow functions where possible
For arrow functions that are both simple and short, we can avoid using explicit `return` to shorten them even further without hurting readability. For the `gulp mozcentral` build-target this reduces the overall size of the output by just under 1 kilo-byte (which isn't a lot but still can't hurt).
This commit is contained in:
parent
6e46304357
commit
9dfe9c552c
22 changed files with 78 additions and 169 deletions
|
@ -4824,9 +4824,7 @@ class StampAnnotation extends MarkupAnnotation {
|
|||
|
||||
const jpegBufferPromise = canvas
|
||||
.convertToBlob({ type: "image/jpeg", quality: 1 })
|
||||
.then(blob => {
|
||||
return blob.arrayBuffer();
|
||||
});
|
||||
.then(blob => blob.arrayBuffer());
|
||||
|
||||
const xobjectName = Name.get("XObject");
|
||||
const imageName = Name.get("Image");
|
||||
|
|
|
@ -691,9 +691,9 @@ async function createBuiltInCMap(name, fetchBuiltInCMap) {
|
|||
const cMap = new CMap(true);
|
||||
|
||||
if (compressionType === CMapCompressionType.BINARY) {
|
||||
return new BinaryCMapReader().process(cMapData, cMap, useCMap => {
|
||||
return extendCMap(cMap, fetchBuiltInCMap, useCMap);
|
||||
});
|
||||
return new BinaryCMapReader().process(cMapData, cMap, useCMap =>
|
||||
extendCMap(cMap, fetchBuiltInCMap, useCMap)
|
||||
);
|
||||
}
|
||||
if (compressionType === CMapCompressionType.NONE) {
|
||||
const lexer = new Lexer(new Stream(cMapData));
|
||||
|
|
|
@ -2093,9 +2093,7 @@ class Font {
|
|||
endOffset: 0,
|
||||
});
|
||||
}
|
||||
locaEntries.sort((a, b) => {
|
||||
return a.offset - b.offset;
|
||||
});
|
||||
locaEntries.sort((a, b) => a.offset - b.offset);
|
||||
// Now the offsets are sorted, calculate the end offset of each glyph.
|
||||
// The last loca entry's endOffset is not calculated since it's the end
|
||||
// of the data and will be stored on the previous entry's endOffset.
|
||||
|
@ -2103,9 +2101,7 @@ class Font {
|
|||
locaEntries[i].endOffset = locaEntries[i + 1].offset;
|
||||
}
|
||||
// Re-sort so glyphs aren't out of order.
|
||||
locaEntries.sort((a, b) => {
|
||||
return a.index - b.index;
|
||||
});
|
||||
locaEntries.sort((a, b) => a.index - b.index);
|
||||
// Calculate the endOffset of the "first" glyph correctly when there are
|
||||
// *multiple* empty ones at the start of the data (fixes issue14618.pdf).
|
||||
for (i = 0; i < numGlyphs; i++) {
|
||||
|
|
|
@ -344,10 +344,9 @@ async function incrementalUpdate({
|
|||
|
||||
// Add a ref for the new xref and sort them
|
||||
newRefs.push({ ref: refForXrefTable, data: "" });
|
||||
newRefs = newRefs.sort((a, b) => {
|
||||
// compare the refs
|
||||
return a.ref.num - b.ref.num;
|
||||
});
|
||||
newRefs = newRefs.sort(
|
||||
(a, b) => /* compare the refs */ a.ref.num - b.ref.num
|
||||
);
|
||||
|
||||
const xrefTableData = [[0, 1, 0xffff]];
|
||||
const indexes = [0, 1];
|
||||
|
|
|
@ -771,19 +771,13 @@ class PDFDocumentProxy {
|
|||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||
// For testing purposes.
|
||||
Object.defineProperty(this, "getXFADatasets", {
|
||||
value: () => {
|
||||
return this._transport.getXFADatasets();
|
||||
},
|
||||
value: () => this._transport.getXFADatasets(),
|
||||
});
|
||||
Object.defineProperty(this, "getXRefPrevValue", {
|
||||
value: () => {
|
||||
return this._transport.getXRefPrevValue();
|
||||
},
|
||||
value: () => this._transport.getXRefPrevValue(),
|
||||
});
|
||||
Object.defineProperty(this, "getAnnotArray", {
|
||||
value: pageIndex => {
|
||||
return this._transport.getAnnotArray(pageIndex);
|
||||
},
|
||||
value: pageIndex => this._transport.getAnnotArray(pageIndex),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1628,9 +1622,7 @@ class PDFPageProxy {
|
|||
if (this._transport._htmlForXfa) {
|
||||
// TODO: We need to revisit this once the XFA foreground patch lands and
|
||||
// only do this for non-foreground XFA.
|
||||
return this.getXfa().then(xfa => {
|
||||
return XfaText.textContent(xfa);
|
||||
});
|
||||
return this.getXfa().then(xfa => XfaText.textContent(xfa));
|
||||
}
|
||||
const readableStream = this.streamTextContent(params);
|
||||
|
||||
|
@ -2358,21 +2350,16 @@ class WorkerTransport {
|
|||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||
// For testing purposes.
|
||||
Object.defineProperty(this, "getXFADatasets", {
|
||||
value: () => {
|
||||
return this.messageHandler.sendWithPromise("GetXFADatasets", null);
|
||||
},
|
||||
value: () =>
|
||||
this.messageHandler.sendWithPromise("GetXFADatasets", null),
|
||||
});
|
||||
Object.defineProperty(this, "getXRefPrevValue", {
|
||||
value: () => {
|
||||
return this.messageHandler.sendWithPromise("GetXRefPrevValue", null);
|
||||
},
|
||||
value: () =>
|
||||
this.messageHandler.sendWithPromise("GetXRefPrevValue", null),
|
||||
});
|
||||
Object.defineProperty(this, "getAnnotArray", {
|
||||
value: pageIndex => {
|
||||
return this.messageHandler.sendWithPromise("GetAnnotArray", {
|
||||
pageIndex,
|
||||
});
|
||||
},
|
||||
value: pageIndex =>
|
||||
this.messageHandler.sendWithPromise("GetAnnotArray", { pageIndex }),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2737,9 +2724,7 @@ class WorkerTransport {
|
|||
|
||||
this.fontLoader
|
||||
.bind(font)
|
||||
.catch(reason => {
|
||||
return messageHandler.sendWithPromise("FontFallback", { id });
|
||||
})
|
||||
.catch(() => messageHandler.sendWithPromise("FontFallback", { id }))
|
||||
.finally(() => {
|
||||
if (!params.fontExtraProperties && font.data) {
|
||||
// Immediately release the `font.data` property once the font
|
||||
|
@ -3013,9 +2998,7 @@ class WorkerTransport {
|
|||
getOptionalContentConfig() {
|
||||
return this.messageHandler
|
||||
.sendWithPromise("GetOptionalContentConfig", null)
|
||||
.then(results => {
|
||||
return new OptionalContentConfig(results);
|
||||
});
|
||||
.then(results => new OptionalContentConfig(results));
|
||||
}
|
||||
|
||||
getPermissions() {
|
||||
|
@ -3192,9 +3175,7 @@ class RenderTask {
|
|||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||
// For testing purposes.
|
||||
Object.defineProperty(this, "getOperatorList", {
|
||||
value: () => {
|
||||
return this.#internalRenderTask.operatorList;
|
||||
},
|
||||
value: () => this.#internalRenderTask.operatorList,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -483,9 +483,9 @@ class DOMStandardFontDataFactory extends BaseStandardFontDataFactory {
|
|||
* @ignore
|
||||
*/
|
||||
_fetchData(url) {
|
||||
return fetchData(url, /* type = */ "arraybuffer").then(data => {
|
||||
return new Uint8Array(data);
|
||||
});
|
||||
return fetchData(url, /* type = */ "arraybuffer").then(
|
||||
data => new Uint8Array(data)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -147,9 +147,8 @@ class PDFFetchStreamReader {
|
|||
this._reader = response.body.getReader();
|
||||
this._headersCapability.resolve();
|
||||
|
||||
const getResponseHeader = name => {
|
||||
return response.headers.get(name);
|
||||
};
|
||||
const getResponseHeader = name => response.headers.get(name);
|
||||
|
||||
const { allowRangeRequests, suggestedLength } =
|
||||
validateRangeRequestCapabilities({
|
||||
getResponseHeader,
|
||||
|
|
|
@ -279,9 +279,8 @@ class PDFNetworkStreamFullRequestReader {
|
|||
const fullRequestXhrId = this._fullRequestId;
|
||||
const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
|
||||
|
||||
const getResponseHeader = name => {
|
||||
return fullRequestXhr.getResponseHeader(name);
|
||||
};
|
||||
const getResponseHeader = name => fullRequestXhr.getResponseHeader(name);
|
||||
|
||||
const { allowRangeRequests, suggestedLength } =
|
||||
validateRangeRequestCapabilities({
|
||||
getResponseHeader,
|
||||
|
|
|
@ -326,11 +326,11 @@ class PDFNodeStreamFullReader extends BaseFullReader {
|
|||
this._headersCapability.resolve();
|
||||
this._setReadableStream(response);
|
||||
|
||||
const getResponseHeader = name => {
|
||||
// Make sure that headers name are in lower case, as mentioned
|
||||
// here: https://nodejs.org/api/http.html#http_message_headers.
|
||||
return this._readableStream.headers[name.toLowerCase()];
|
||||
};
|
||||
// Make sure that headers name are in lower case, as mentioned
|
||||
// here: https://nodejs.org/api/http.html#http_message_headers.
|
||||
const getResponseHeader = name =>
|
||||
this._readableStream.headers[name.toLowerCase()];
|
||||
|
||||
const { allowRangeRequests, suggestedLength } =
|
||||
validateRangeRequestCapabilities({
|
||||
getResponseHeader,
|
||||
|
|
|
@ -141,9 +141,7 @@ class Sandbox {
|
|||
}
|
||||
|
||||
function QuickJSSandbox() {
|
||||
return ModuleLoader().then(module => {
|
||||
return new Sandbox(window, module);
|
||||
});
|
||||
return ModuleLoader().then(module => new Sandbox(window, module));
|
||||
}
|
||||
|
||||
export { QuickJSSandbox };
|
||||
|
|
|
@ -212,66 +212,26 @@ class Util extends PDFObject {
|
|||
}
|
||||
|
||||
const handlers = {
|
||||
mmmm: data => {
|
||||
return this._months[data.month];
|
||||
},
|
||||
mmm: data => {
|
||||
return this._months[data.month].substring(0, 3);
|
||||
},
|
||||
mm: data => {
|
||||
return (data.month + 1).toString().padStart(2, "0");
|
||||
},
|
||||
m: data => {
|
||||
return (data.month + 1).toString();
|
||||
},
|
||||
dddd: data => {
|
||||
return this._days[data.dayOfWeek];
|
||||
},
|
||||
ddd: data => {
|
||||
return this._days[data.dayOfWeek].substring(0, 3);
|
||||
},
|
||||
dd: data => {
|
||||
return data.day.toString().padStart(2, "0");
|
||||
},
|
||||
d: data => {
|
||||
return data.day.toString();
|
||||
},
|
||||
yyyy: data => {
|
||||
return data.year.toString();
|
||||
},
|
||||
yy: data => {
|
||||
return (data.year % 100).toString().padStart(2, "0");
|
||||
},
|
||||
HH: data => {
|
||||
return data.hours.toString().padStart(2, "0");
|
||||
},
|
||||
H: data => {
|
||||
return data.hours.toString();
|
||||
},
|
||||
hh: data => {
|
||||
return (1 + ((data.hours + 11) % 12)).toString().padStart(2, "0");
|
||||
},
|
||||
h: data => {
|
||||
return (1 + ((data.hours + 11) % 12)).toString();
|
||||
},
|
||||
MM: data => {
|
||||
return data.minutes.toString().padStart(2, "0");
|
||||
},
|
||||
M: data => {
|
||||
return data.minutes.toString();
|
||||
},
|
||||
ss: data => {
|
||||
return data.seconds.toString().padStart(2, "0");
|
||||
},
|
||||
s: data => {
|
||||
return data.seconds.toString();
|
||||
},
|
||||
tt: data => {
|
||||
return data.hours < 12 ? "am" : "pm";
|
||||
},
|
||||
t: data => {
|
||||
return data.hours < 12 ? "a" : "p";
|
||||
},
|
||||
mmmm: data => this._months[data.month],
|
||||
mmm: data => this._months[data.month].substring(0, 3),
|
||||
mm: data => (data.month + 1).toString().padStart(2, "0"),
|
||||
m: data => (data.month + 1).toString(),
|
||||
dddd: data => this._days[data.dayOfWeek],
|
||||
ddd: data => this._days[data.dayOfWeek].substring(0, 3),
|
||||
dd: data => data.day.toString().padStart(2, "0"),
|
||||
d: data => data.day.toString(),
|
||||
yyyy: data => data.year.toString(),
|
||||
yy: data => (data.year % 100).toString().padStart(2, "0"),
|
||||
HH: data => data.hours.toString().padStart(2, "0"),
|
||||
H: data => data.hours.toString(),
|
||||
hh: data => (1 + ((data.hours + 11) % 12)).toString().padStart(2, "0"),
|
||||
h: data => (1 + ((data.hours + 11) % 12)).toString(),
|
||||
MM: data => data.minutes.toString().padStart(2, "0"),
|
||||
M: data => data.minutes.toString(),
|
||||
ss: data => data.seconds.toString().padStart(2, "0"),
|
||||
s: data => data.seconds.toString(),
|
||||
tt: data => (data.hours < 12 ? "am" : "pm"),
|
||||
t: data => (data.hours < 12 ? "a" : "p"),
|
||||
};
|
||||
|
||||
const data = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue