1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Use more for...of loops in the code-base

Note that these cases, which are all in older code, were found using the [`unicorn/no-for-loop`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-for-loop.md) ESLint plugin rule.
However, note that I've opted not to enable this rule by default since there's still *some* cases where I do think that it makes sense to allow "regular" for-loops.
This commit is contained in:
Jonas Jenwald 2022-07-17 15:48:39 +02:00
parent 5bfba89b0a
commit 37ebc28756
14 changed files with 35 additions and 50 deletions

View file

@ -301,8 +301,8 @@ window.onload = function () {
// Bind an event handler to each image link
const images = document.getElementsByClassName("image");
for (let i = 0; i < images.length; i++) {
images[i].addEventListener(
for (const image of images) {
image.addEventListener(
"click",
function (e) {
showImages(e.target.id);
@ -407,9 +407,9 @@ window.onload = function () {
function flashPixels(on) {
const stroke = on ? "#FF0000" : "#CCC";
const strokeWidth = on ? "2px" : "1px";
for (let i = 0; i < gFlashingPixels.length; i++) {
gFlashingPixels[i].setAttribute("stroke", stroke);
gFlashingPixels[i].setAttribute("stroke-width", strokeWidth);
for (const pixel of gFlashingPixels) {
pixel.setAttribute("stroke", stroke);
pixel.setAttribute("stroke-width", strokeWidth);
}
}

View file

@ -30,17 +30,13 @@ function parseOptions() {
function group(stats, groupBy) {
const vals = [];
for (let i = 0; i < stats.length; i++) {
const curStat = stats[i];
for (const curStat of stats) {
const keyArr = [];
for (let j = 0; j < groupBy.length; j++) {
keyArr.push(curStat[groupBy[j]]);
for (const entry of groupBy) {
keyArr.push(curStat[entry]);
}
const key = keyArr.join(",");
if (vals[key] === undefined) {
vals[key] = [];
}
vals[key].push(curStat.time);
(vals[key] ||= []).push(curStat.time);
}
return vals;
}
@ -134,8 +130,7 @@ function stat(baseline, current) {
return s.length;
});
rows.push(labels);
for (let k = 0; k < keys.length; k++) {
const key = keys[k];
for (const key of keys) {
const baselineMean = mean(baselineGroup[key]);
const currentMean = mean(currentGroup[key]);
const row = key.split(",");
@ -172,8 +167,7 @@ function stat(baseline, current) {
// print output
console.log("-- Grouped By " + options.groupBy.join(", ") + " --");
const groupCount = options.groupBy.length;
for (let r = 0; r < rows.length; r++) {
const row = rows[r];
for (const row of rows) {
for (let i = 0; i < row.length; i++) {
row[i] = pad(row[i], width[i], i < groupCount ? "right" : "left");
}

View file

@ -416,10 +416,10 @@ describe("function", function () {
"destOffset",
compiledCode
);
for (let i = 0; i < samples.length; i++) {
const out = new Float32Array(samples[i].output.length);
fn(samples[i].input, 0, out, 0);
expect(Array.prototype.slice.call(out, 0)).toEqual(samples[i].output);
for (const { input, output } of samples) {
const out = new Float32Array(output.length);
fn(input, 0, out, 0);
expect(Array.prototype.slice.call(out, 0)).toEqual(output);
}
}
}