mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
Convert files in the src/display/
-folder to use optional chaining where possible
By using optional chaining, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining, it's possible to reduce unnecessary code-repetition in many cases. Note that these changes also reduce the size of the *built* `pdf.js` file, when `SKIP_BABEL == true` is set, and for the `MOZCENTRAL` build-target that result in a `0.1%` filesize reduction from a simple and mostly mechanical code change.
This commit is contained in:
parent
e3851a6765
commit
1dad255784
8 changed files with 19 additions and 41 deletions
|
@ -1566,9 +1566,7 @@ class PDFPageProxy {
|
|||
return;
|
||||
}
|
||||
}
|
||||
intentState.streamReader.cancel(
|
||||
new AbortException(reason && reason.message)
|
||||
);
|
||||
intentState.streamReader.cancel(new AbortException(reason?.message));
|
||||
intentState.streamReader = null;
|
||||
|
||||
if (this._transport.destroyed) {
|
||||
|
@ -1615,8 +1613,7 @@ class LoopbackPort {
|
|||
let buffer, result;
|
||||
if ((buffer = value.buffer) && isArrayBuffer(buffer)) {
|
||||
// We found object with ArrayBuffer (typed array).
|
||||
const transferable = transfers && transfers.includes(buffer);
|
||||
if (transferable) {
|
||||
if (transfers?.includes(buffer)) {
|
||||
result = new value.constructor(
|
||||
buffer,
|
||||
value.byteOffset,
|
||||
|
@ -1712,8 +1709,7 @@ const PDFWorker = (function PDFWorkerClosure() {
|
|||
fallbackWorkerSrc = "./pdf.worker.js";
|
||||
}
|
||||
} else if (typeof document === "object" && "currentScript" in document) {
|
||||
const pdfjsFilePath =
|
||||
document.currentScript && document.currentScript.src;
|
||||
const pdfjsFilePath = document.currentScript?.src;
|
||||
if (pdfjsFilePath) {
|
||||
fallbackWorkerSrc = pdfjsFilePath.replace(
|
||||
/(\.(?:min\.)?js)(\?.*)?$/i,
|
||||
|
@ -1739,8 +1735,7 @@ const PDFWorker = (function PDFWorkerClosure() {
|
|||
function getMainThreadWorkerMessageHandler() {
|
||||
let mainWorkerMessageHandler;
|
||||
try {
|
||||
mainWorkerMessageHandler =
|
||||
globalThis.pdfjsWorker && globalThis.pdfjsWorker.WorkerMessageHandler;
|
||||
mainWorkerMessageHandler = globalThis.pdfjsWorker?.WorkerMessageHandler;
|
||||
} catch (ex) {
|
||||
/* Ignore errors. */
|
||||
}
|
||||
|
@ -2378,11 +2373,7 @@ class WorkerTransport {
|
|||
}
|
||||
|
||||
let fontRegistry = null;
|
||||
if (
|
||||
params.pdfBug &&
|
||||
globalThis.FontInspector &&
|
||||
globalThis.FontInspector.enabled
|
||||
) {
|
||||
if (params.pdfBug && globalThis.FontInspector?.enabled) {
|
||||
fontRegistry = {
|
||||
registerFont(font, url) {
|
||||
globalThis.FontInspector.fontAdded(font, url);
|
||||
|
@ -2441,11 +2432,7 @@ class WorkerTransport {
|
|||
|
||||
// Heuristic that will allow us not to store large data.
|
||||
const MAX_IMAGE_SIZE_TO_STORE = 8000000;
|
||||
if (
|
||||
imageData &&
|
||||
"data" in imageData &&
|
||||
imageData.data.length > MAX_IMAGE_SIZE_TO_STORE
|
||||
) {
|
||||
if (imageData?.data?.length > MAX_IMAGE_SIZE_TO_STORE) {
|
||||
pageProxy.cleanupAfterRender = true;
|
||||
}
|
||||
break;
|
||||
|
@ -2868,11 +2855,7 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
|
|||
canvasInRendering.add(this._canvas);
|
||||
}
|
||||
|
||||
if (
|
||||
this._pdfBug &&
|
||||
globalThis.StepperManager &&
|
||||
globalThis.StepperManager.enabled
|
||||
) {
|
||||
if (this._pdfBug && globalThis.StepperManager?.enabled) {
|
||||
this.stepper = globalThis.StepperManager.create(this._pageIndex);
|
||||
this.stepper.init(this.operatorList);
|
||||
this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue