Enable the no-var linting rule in src/core/worker.js

This is done automatically with `gulp lint --fix` and the following
manual changes:

```diff
diff --git a/src/core/worker.js b/src/core/worker.js
index aec9c1d39..f88691622 100644
--- a/src/core/worker.js
+++ b/src/core/worker.js
@@ -300,7 +300,7 @@ class WorkerMessageHandler {
         cachedChunks = [];
       };
       const readPromise = new Promise(function (resolve, reject) {
-        var readChunk = function ({ value, done }) {
+        const readChunk = function ({ value, done }) {
           try {
             ensureNotTerminated();
             if (done) {
```
This commit is contained in:
Tim van der Meij 2021-04-25 15:51:20 +02:00
parent 85659b4cf0
commit 16efd09c9f
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762

View File

@ -12,7 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable no-var */
import {
AbortException,
@ -69,7 +68,7 @@ class WorkerTask {
class WorkerMessageHandler {
static setup(handler, port) {
var testMessageProcessed = false;
let testMessageProcessed = false;
handler.on("test", function wphSetupTest(data) {
if (testMessageProcessed) {
return; // we already processed 'test' message once
@ -100,10 +99,10 @@ class WorkerMessageHandler {
static createDocumentHandler(docParams, port) {
// This context is actually holds references on pdfManager and handler,
// until the latter is destroyed.
var pdfManager;
var terminated = false;
var cancelXHRs = null;
var WorkerTasks = [];
let pdfManager;
let terminated = false;
let cancelXHRs = null;
const WorkerTasks = [];
const verbosity = getVerbosityLevel();
const apiVersion = docParams.apiVersion;
@ -152,10 +151,10 @@ class WorkerMessageHandler {
}
}
var docId = docParams.docId;
var docBaseUrl = docParams.docBaseUrl;
var workerHandlerName = docParams.docId + "_worker";
var handler = new MessageHandler(workerHandlerName, docId, port);
const docId = docParams.docId;
const docBaseUrl = docParams.docBaseUrl;
const workerHandlerName = docParams.docId + "_worker";
let handler = new MessageHandler(workerHandlerName, docId, port);
// Ensure that postMessage transfers are always correctly enabled/disabled,
// to prevent "DataCloneError" in browsers without transfers support.
@ -173,7 +172,7 @@ class WorkerMessageHandler {
function finishWorkerTask(task) {
task.finish();
var i = WorkerTasks.indexOf(task);
const i = WorkerTasks.indexOf(task);
WorkerTasks.splice(i, 1);
}
@ -208,10 +207,10 @@ class WorkerMessageHandler {
}
function getPdfManager(data, evaluatorOptions, enableXfa) {
var pdfManagerCapability = createPromiseCapability();
const pdfManagerCapability = createPromiseCapability();
let newPdfManager;
var source = data.source;
const source = data.source;
if (source.data) {
try {
newPdfManager = new LocalPdfManager(
@ -229,7 +228,7 @@ class WorkerMessageHandler {
return pdfManagerCapability.promise;
}
var pdfStream,
let pdfStream,
cachedChunks = [];
try {
pdfStream = new PDFWorkerStream(handler);
@ -238,7 +237,7 @@ class WorkerMessageHandler {
return pdfManagerCapability.promise;
}
var fullRequest = pdfStream.getFullReader();
const fullRequest = pdfStream.getFullReader();
fullRequest.headersReady
.then(function () {
if (!fullRequest.isRangeSupported) {
@ -246,7 +245,7 @@ class WorkerMessageHandler {
}
// We don't need auto-fetch when streaming is enabled.
var disableAutoFetch =
const disableAutoFetch =
source.disableAutoFetch || fullRequest.isStreamingSupported;
newPdfManager = new NetworkPdfManager(
docId,
@ -278,9 +277,9 @@ class WorkerMessageHandler {
cancelXHRs = null;
});
var loaded = 0;
var flushChunks = function () {
var pdfFile = arraysToBytes(cachedChunks);
let loaded = 0;
const flushChunks = function () {
const pdfFile = arraysToBytes(cachedChunks);
if (source.length && pdfFile.length !== source.length) {
warn("reported HTTP length is different from actual");
}
@ -300,8 +299,8 @@ class WorkerMessageHandler {
}
cachedChunks = [];
};
var readPromise = new Promise(function (resolve, reject) {
var readChunk = function ({ value, done }) {
const readPromise = new Promise(function (resolve, reject) {
const readChunk = function ({ value, done }) {
try {
ensureNotTerminated();
if (done) {
@ -355,7 +354,7 @@ class WorkerMessageHandler {
ensureNotTerminated();
if (ex instanceof PasswordException) {
var task = new WorkerTask(`PasswordException: response ${ex.code}`);
const task = new WorkerTask(`PasswordException: response ${ex.code}`);
startWorkerTask(task);
handler
@ -406,7 +405,7 @@ class WorkerMessageHandler {
ensureNotTerminated();
var evaluatorOptions = {
const evaluatorOptions = {
maxImageSize: data.maxImageSize,
disableFontFace: data.disableFontFace,
ignoreErrors: data.ignoreErrors,
@ -656,9 +655,9 @@ class WorkerMessageHandler {
);
handler.on("GetOperatorList", function wphSetupRenderPage(data, sink) {
var pageIndex = data.pageIndex;
const pageIndex = data.pageIndex;
pdfManager.getPage(pageIndex).then(function (page) {
var task = new WorkerTask(`GetOperatorList: page ${pageIndex}`);
const task = new WorkerTask(`GetOperatorList: page ${pageIndex}`);
startWorkerTask(task);
// NOTE: Keep this condition in sync with the `info` helper function.
@ -707,12 +706,12 @@ class WorkerMessageHandler {
});
handler.on("GetTextContent", function wphExtractText(data, sink) {
var pageIndex = data.pageIndex;
const pageIndex = data.pageIndex;
sink.onPull = function (desiredSize) {};
sink.onCancel = function (reason) {};
pdfManager.getPage(pageIndex).then(function (page) {
var task = new WorkerTask("GetTextContent: page " + pageIndex);
const task = new WorkerTask("GetTextContent: page " + pageIndex);
startWorkerTask(task);
// NOTE: Keep this condition in sync with the `info` helper function.
@ -806,7 +805,7 @@ class WorkerMessageHandler {
}
static initializeFromPort(port) {
var handler = new MessageHandler("worker", "main", port);
const handler = new MessageHandler("worker", "main", port);
WorkerMessageHandler.setup(handler, port);
handler.send("ready", null);
}