1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 01:58:06 +02:00

Replace a bunch of Array.prototype.forEach() cases with for...of loops instead

Using `for...of` is a modern and generally much nicer pattern, since it gets rid of unnecessary callback-functions. (In a couple of spots, a "regular" `for` loop had to be used.)
This commit is contained in:
Jonas Jenwald 2021-04-24 12:36:01 +02:00
parent da0e7ea969
commit da22146b95
14 changed files with 67 additions and 71 deletions

View file

@ -1394,9 +1394,9 @@ class PartialEvaluator {
) {
const groupIds = [];
if (Array.isArray(optionalContentGroups)) {
optionalContent.get("OCGs").forEach(ocg => {
for (const ocg of optionalContentGroups) {
groupIds.push(ocg.toString());
});
}
} else {
// Dictionary, just use the obj id.
groupIds.push(optionalContentGroups.objId);

View file

@ -1337,13 +1337,14 @@ var PostScriptCompiler = (function PostScriptCompilerClosure() {
}
var result = [];
instructions.forEach(function (instruction) {
var statementBuilder = new ExpressionBuilderVisitor();
for (const instruction of instructions) {
const statementBuilder = new ExpressionBuilderVisitor();
instruction.visit(statementBuilder);
result.push(statementBuilder.toString());
});
stack.forEach(function (expr, i) {
var statementBuilder = new ExpressionBuilderVisitor();
}
for (let i = 0, ii = stack.length; i < ii; i++) {
const expr = stack[i],
statementBuilder = new ExpressionBuilderVisitor();
expr.visit(statementBuilder);
var min = range[i * 2],
max = range[i * 2 + 1];
@ -1359,7 +1360,7 @@ var PostScriptCompiler = (function PostScriptCompilerClosure() {
out.unshift("dest[destOffset + ", i, "] = ");
out.push(";");
result.push(out.join(""));
});
}
return result.join("\n");
}
}

View file

@ -785,10 +785,10 @@ class WorkerMessageHandler {
cancelXHRs(new AbortException("Worker was terminated."));
}
WorkerTasks.forEach(function (task) {
for (const task of WorkerTasks) {
waitOn.push(task.finished);
task.terminate();
});
}
return Promise.all(waitOn).then(function () {
// Notice that even if we destroying handler, resolved response promise

View file

@ -43,10 +43,9 @@ class PDFWorkerStream {
if (this._fullRequestReader) {
this._fullRequestReader.cancel(reason);
}
const readers = this._rangeRequestReaders.slice(0);
readers.forEach(function (reader) {
for (const reader of this._rangeRequestReaders.slice(0)) {
reader.cancel(reason);
});
}
}
}