mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-11-30 16:37:18 +01:00
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:
@@ -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(
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Vendored
+1
-1
@@ -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
@@ -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)
|
||||
|
||||
Vendored
+1
-1
@@ -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
@@ -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
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user