1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 06:38:07 +02:00

Use arrow function with various Array methods

A lot of this is quite old code, which we can shorten slightly by using arrow functions instead of "regular" functions.
This commit is contained in:
Jonas Jenwald 2025-03-02 14:48:08 +01:00
parent 7081a1f112
commit 2e62f426fe
10 changed files with 16 additions and 46 deletions

View file

@ -414,9 +414,7 @@ class ChunkedStreamManager {
}
}
chunksToRequest.sort(function (a, b) {
return a - b;
});
chunksToRequest.sort((a, b) => a - b);
return this._requestChunks(chunksToRequest);
}

View file

@ -576,9 +576,7 @@ function getRanges(glyphs, toUnicodeExtraMap, numGlyphs) {
if (codes.length === 0) {
codes.push({ fontCharCode: 0, glyphId: 0 });
}
codes.sort(function fontGetRangesSort(a, b) {
return a.fontCharCode - b.fontCharCode;
});
codes.sort((a, b) => a.fontCharCode - b.fontCharCode);
// Split the sorted codes into ranges.
const ranges = [];
@ -1777,9 +1775,7 @@ class Font {
}
// removing duplicate entries
mappings.sort(function (a, b) {
return a.charCode - b.charCode;
});
mappings.sort((a, b) => a.charCode - b.charCode);
const finalMappings = [],
seenCharCodes = new Set();
for (const map of mappings) {

View file

@ -374,9 +374,7 @@ function decodeBitmap(
// Sorting is non-standard, and it is not required. But sorting increases
// the number of template bits that can be reused from the previous
// contextLabel in the main loop.
template.sort(function (a, b) {
return a.y - b.y || a.x - b.x;
});
template.sort((a, b) => a.y - b.y || a.x - b.x);
const templateLength = template.length;
const templateX = new Int8Array(templateLength);

View file

@ -321,11 +321,7 @@ class SimpleDOMNode {
if (!this.childNodes) {
return this.nodeValue || "";
}
return this.childNodes
.map(function (child) {
return child.textContent;
})
.join("");
return this.childNodes.map(child => child.textContent).join("");
}
get children() {

View file

@ -49,10 +49,7 @@ async function initializePDFJS(callback) {
"pdfjs-test/font/font_os2_spec.js",
"pdfjs-test/font/font_post_spec.js",
"pdfjs-test/font/font_fpgm_spec.js",
].map(function (moduleName) {
// eslint-disable-next-line no-unsanitized/method
return import(moduleName);
})
].map(moduleName => import(moduleName)) // eslint-disable-line no-unsanitized/method
);
callback();

View file

@ -64,9 +64,7 @@ function flatten(stats) {
});
// Use only overall results if not grouped by 'stat'
if (!options.groupBy.includes("stat")) {
rows = rows.filter(function (s) {
return s.stat === "Overall";
});
rows = rows.filter(s => s.stat === "Overall");
}
return rows;
}
@ -129,9 +127,7 @@ function stat(baseline, current) {
}
const rows = [];
// collect rows and measure column widths
const width = labels.map(function (s) {
return s.length;
});
const width = labels.map(s => s.length);
rows.push(labels);
for (const key of keys) {
const baselineMean = mean(baselineGroup[key]);
@ -162,9 +158,7 @@ function stat(baseline, current) {
}
// add horizontal line
const hline = width.map(function (w) {
return new Array(w + 1).join("-");
});
const hline = width.map(w => new Array(w + 1).join("-"));
rows.splice(1, 0, hline);
// print output

View file

@ -1051,9 +1051,7 @@ async function closeSession(browser) {
await session.browser.close();
}
session.closed = true;
const allClosed = sessions.every(function (s) {
return s.closed;
});
const allClosed = sessions.every(s => s.closed);
if (allClosed) {
if (tempDir) {
fs.rmSync(tempDir, { recursive: true, force: true });

View file

@ -4869,9 +4869,9 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
// Issue 6205 reported an issue with font rendering, so clear the loaded
// fonts so that we can see whether loading PDFs in parallel does not
// cause any issues with the rendered fonts.
const destroyPromises = loadingTasks.map(function (loadingTask) {
return loadingTask.destroy();
});
const destroyPromises = loadingTasks.map(loadingTask =>
loadingTask.destroy()
);
await Promise.all(destroyPromises);
});

View file

@ -100,10 +100,7 @@ async function initializePDFJS(callback) {
"pdfjs-test/unit/xfa_serialize_data_spec.js",
"pdfjs-test/unit/xfa_tohtml_spec.js",
"pdfjs-test/unit/xml_spec.js",
].map(function (moduleName) {
// eslint-disable-next-line no-unsanitized/method
return import(moduleName);
})
].map(moduleName => import(moduleName)) // eslint-disable-line no-unsanitized/method
);
if (isNodeJS) {

View file

@ -398,9 +398,7 @@ class Stepper {
}
getNextBreakPoint() {
this.breakPoints.sort(function (a, b) {
return a - b;
});
this.breakPoints.sort((a, b) => a - b);
for (const breakPoint of this.breakPoints) {
if (breakPoint > this.currentIdx) {
return breakPoint;
@ -487,9 +485,7 @@ const Stats = (function Stats() {
statsDiv.textContent = stat.toString();
wrapper.append(title, statsDiv);
stats.push({ pageNumber, div: wrapper });
stats.sort(function (a, b) {
return a.pageNumber - b.pageNumber;
});
stats.sort((a, b) => a.pageNumber - b.pageNumber);
clear(this.panel);
for (const entry of stats) {
this.panel.append(entry.div);