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) { chunksToRequest.sort((a, b) => a - b);
return a - b;
});
return this._requestChunks(chunksToRequest); return this._requestChunks(chunksToRequest);
} }

View file

@ -576,9 +576,7 @@ function getRanges(glyphs, toUnicodeExtraMap, numGlyphs) {
if (codes.length === 0) { if (codes.length === 0) {
codes.push({ fontCharCode: 0, glyphId: 0 }); codes.push({ fontCharCode: 0, glyphId: 0 });
} }
codes.sort(function fontGetRangesSort(a, b) { codes.sort((a, b) => a.fontCharCode - b.fontCharCode);
return a.fontCharCode - b.fontCharCode;
});
// Split the sorted codes into ranges. // Split the sorted codes into ranges.
const ranges = []; const ranges = [];
@ -1777,9 +1775,7 @@ class Font {
} }
// removing duplicate entries // removing duplicate entries
mappings.sort(function (a, b) { mappings.sort((a, b) => a.charCode - b.charCode);
return a.charCode - b.charCode;
});
const finalMappings = [], const finalMappings = [],
seenCharCodes = new Set(); seenCharCodes = new Set();
for (const map of mappings) { 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 // Sorting is non-standard, and it is not required. But sorting increases
// the number of template bits that can be reused from the previous // the number of template bits that can be reused from the previous
// contextLabel in the main loop. // contextLabel in the main loop.
template.sort(function (a, b) { template.sort((a, b) => a.y - b.y || a.x - b.x);
return a.y - b.y || a.x - b.x;
});
const templateLength = template.length; const templateLength = template.length;
const templateX = new Int8Array(templateLength); const templateX = new Int8Array(templateLength);

View file

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

View file

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

View file

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

View file

@ -1051,9 +1051,7 @@ async function closeSession(browser) {
await session.browser.close(); await session.browser.close();
} }
session.closed = true; session.closed = true;
const allClosed = sessions.every(function (s) { const allClosed = sessions.every(s => s.closed);
return s.closed;
});
if (allClosed) { if (allClosed) {
if (tempDir) { if (tempDir) {
fs.rmSync(tempDir, { recursive: true, force: true }); 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 // 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 // fonts so that we can see whether loading PDFs in parallel does not
// cause any issues with the rendered fonts. // cause any issues with the rendered fonts.
const destroyPromises = loadingTasks.map(function (loadingTask) { const destroyPromises = loadingTasks.map(loadingTask =>
return loadingTask.destroy(); loadingTask.destroy()
}); );
await Promise.all(destroyPromises); 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_serialize_data_spec.js",
"pdfjs-test/unit/xfa_tohtml_spec.js", "pdfjs-test/unit/xfa_tohtml_spec.js",
"pdfjs-test/unit/xml_spec.js", "pdfjs-test/unit/xml_spec.js",
].map(function (moduleName) { ].map(moduleName => import(moduleName)) // eslint-disable-line no-unsanitized/method
// eslint-disable-next-line no-unsanitized/method
return import(moduleName);
})
); );
if (isNodeJS) { if (isNodeJS) {

View file

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