Replace forEach callback functions with arrow functions

This improves consistency in the code-base, and it's also a tiny bit shorter which cannot hurt.
This commit is contained in:
Jonas Jenwald
2026-09-09 13:56:07 +02:00
parent 248bdcc235
commit 9cad39aec7
13 changed files with 26 additions and 26 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ function buildSVG(viewport, textContent) {
svg.setAttribute("font-size", 1);
// processing all items
textContent.items.forEach(function (textItem) {
textContent.items.forEach(textItem => {
// we have to take in account viewport transform, which includes scale,
// rotation and Y-axis flip, and not forgetting to flip text.
const tx = pdfjsLib.Util.transform(
+3 -3
View File
@@ -62,7 +62,7 @@ Promise.all([
var prefNames = Object.keys(schema);
var renderPreferenceFunctions = {};
// Render options
prefNames.forEach(function (prefName) {
prefNames.forEach(prefName => {
var prefSchema = schema[prefName];
if (!prefSchema.title) {
// Don't show preferences if the title is missing.
@@ -105,7 +105,7 @@ Promise.all([
document.getElementById("reset-button").onclick = function () {
userPrefs = {};
storageArea.remove(prefNames, function () {
renderedPrefNames.forEach(function (prefName) {
renderedPrefNames.forEach(prefName => {
renderPreferenceFunctions[prefName](getPrefValue(prefName));
});
});
@@ -120,7 +120,7 @@ Promise.all([
prefs = managedPrefs;
}
if (prefs) {
renderedPrefNames.forEach(function (prefName) {
renderedPrefNames.forEach(prefName => {
var prefChanges = changes[prefName];
if (prefChanges) {
if ("newValue" in prefChanges) {
+1 -1
View File
@@ -11,7 +11,7 @@ const files = fs
.readdirSync(baseDir)
.filter(name => /-expected\./.test(name))
.map(name => path.join(baseDir, name));
files.forEach(function (expectationFilename) {
files.forEach(expectationFilename => {
const inFilename = expectationFilename.replace("-expected", "");
const expectation = fs
.readFileSync(expectationFilename)
+1 -1
View File
@@ -11,7 +11,7 @@ const files = fs
.readdirSync(baseDir)
.filter(name => /-expected\./.test(name))
.map(name => path.join(baseDir, name));
files.forEach(function (expectationFilename) {
files.forEach(expectationFilename => {
const inFilename = expectationFilename.replace("-expected", "");
const expectation = fs
.readFileSync(expectationFilename)
+1 -1
View File
@@ -473,7 +473,7 @@ function compressCmaps(src, dest, verify) {
const files = fs.readdirSync(src).filter(
fn => !fn.includes(".") // skipping files with the extension
);
files.forEach(function (fn) {
files.forEach(fn => {
const srcPath = path.join(src, fn);
const destPath = path.join(dest, fn + ".bcmap");
const stats = compressCmap(srcPath, destPath, verify);
+1 -1
View File
@@ -1384,7 +1384,7 @@ gulp.task("cmaps", async function () {
}
// Remove old bcmap files.
fs.readdirSync(VIEWER_CMAP_OUTPUT).forEach(function (file) {
fs.readdirSync(VIEWER_CMAP_OUTPUT).forEach(file => {
if (/\.bcmap$/i.test(file)) {
fs.unlinkSync(VIEWER_CMAP_OUTPUT + "/" + file);
}
+1 -1
View File
@@ -660,7 +660,7 @@ async function extendCMap(cMap, fetchBuiltInCMap, useCMap) {
}
// Merge the map into the current one, making sure not to override
// any previously defined entries.
cMap.useCMap.forEach(function (key, value) {
cMap.useCMap.forEach((key, value) => {
if (!cMap.contains(key)) {
cMap.mapOne(key, value);
}
+2 -2
View File
@@ -4006,7 +4006,7 @@ class PartialEvaluator {
});
const toUnicode = [],
buf = [];
properties.cMap.forEach(function (charcode, cid) {
properties.cMap.forEach((charcode, cid) => {
if (cid > 0xffff) {
throw new FormatError("Max size of CID is 65,535");
}
@@ -4060,7 +4060,7 @@ class PartialEvaluator {
// Convert UTF-16BE
// NOTE: cmap can be a sparse array, so use forEach instead of
// `for(;;)` to iterate over all keys.
cmap.forEach(function (charCode, token) {
cmap.forEach((charCode, token) => {
// Some cmaps contain *only* CID characters (fixes issue9367.pdf).
if (typeof token === "number") {
map[charCode] = String.fromCodePoint(token);
+4 -4
View File
@@ -1340,7 +1340,7 @@ class Font {
properties.hasIncludedToUnicodeMap &&
this.toUnicode instanceof IdentityToUnicodeMap
) {
this.toUnicode.forEach(function (charCode, unicodeCharCode) {
this.toUnicode.forEach((charCode, unicodeCharCode) => {
const cid = map[charCode];
if (cidToGidMap[cid] === undefined) {
map[charCode] = unicodeCharCode;
@@ -1350,7 +1350,7 @@ class Font {
}
if (!(this.toUnicode instanceof IdentityToUnicodeMap)) {
this.toUnicode.forEach(function (charCode, unicodeCharCode) {
this.toUnicode.forEach((charCode, unicodeCharCode) => {
map[charCode] = unicodeCharCode;
});
}
@@ -1385,7 +1385,7 @@ class Font {
!this.cidEncoding.startsWith("Identity-") &&
!(this.toUnicode instanceof IdentityToUnicodeMap)
) {
this.toUnicode.forEach(function (charCode, unicodeCharCode) {
this.toUnicode.forEach((charCode, unicodeCharCode) => {
map[charCode] = unicodeCharCode;
});
}
@@ -3039,7 +3039,7 @@ class Font {
const cidToGidMap = properties.cidToGidMap || [];
const isCidToGidMapEmpty = cidToGidMap.length === 0;
properties.cMap.forEach(function (charCode, cid) {
properties.cMap.forEach((charCode, cid) => {
if (typeof cid === "string") {
cid = convertCidString(charCode, cid, /* shouldThrow = */ true);
}
+2 -2
View File
@@ -96,7 +96,7 @@ function createExtensionGlobal() {
};
window.Headers = function (headers) {
headers = JSON.parse(JSON.stringify(headers)); // Clone.
Object.keys(headers).forEach(function (k) {
Object.keys(headers).forEach(k => {
headers[k] = String(headers[k]);
});
return headers;
@@ -142,7 +142,7 @@ function createExtensionGlobal() {
};
window.test_fireTimers = function () {
assert.ok(timers.length);
timers.forEach(function (timer) {
timers.forEach(timer => {
timer();
});
};
+2 -2
View File
@@ -48,8 +48,8 @@ function group(stats, groupBy) {
*/
function flatten(stats) {
let rows = [];
stats.forEach(function (curStat) {
curStat.stats.forEach(function (s) {
stats.forEach(curStat => {
curStat.stats.forEach(s => {
rows.push({
browser: curStat.browser,
page: curStat.page,
+6 -6
View File
@@ -240,7 +240,7 @@ async function startRefTest(masterMode, showRefImages) {
var numFBFFailures = 0;
var numEqFailures = 0;
var numEqNoSnapshot = 0;
sessions.forEach(function (session) {
sessions.forEach(session => {
numRuns += session.numRuns;
numErrors += session.numErrors;
numFBFFailures += session.numFBFFailures;
@@ -699,8 +699,8 @@ async function checkRefTestResults(browser, id, results) {
var task = session.tasks[id];
session.numRuns++;
results.forEach(function (roundResults, round) {
roundResults.forEach(function (pageResult, page) {
results.forEach((roundResults, round) => {
roundResults.forEach((pageResult, page) => {
if (!pageResult) {
return; // no results
}
@@ -760,8 +760,8 @@ async function checkRefTestResults(browser, id, results) {
}
}
// Clear snapshot buffers and drop the task entry from the session.
results.forEach(function (roundResults) {
roundResults.forEach(function (pageResult) {
results.forEach(roundResults => {
roundResults.forEach(pageResult => {
if (pageResult) {
pageResult.snapshot = null;
pageResult.baselineSnapshot = null;
@@ -853,7 +853,7 @@ function onAllSessionsClosedAfterTests(name) {
stopServer();
var numRuns = 0,
numErrors = 0;
sessions.forEach(function (session) {
sessions.forEach(session => {
numRuns += session.numRuns;
numErrors += session.numErrors;
});
+1 -1
View File
@@ -21,7 +21,7 @@ function copySubtreeSync(src, dest) {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest);
}
files.forEach(function (filename) {
files.forEach(filename => {
const srcFile = path.join(src, filename);
const file = path.join(dest, filename);
const stats = fs.statSync(srcFile);