From fb9b574f3d2c7b69b067dd87350c56cfef6725a9 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 16 Jun 2020 11:44:33 +0200 Subject: [PATCH] Convert the code in `src/core/worker.js` to use ES6 classes This removes one instance of `// eslint-disable-next-line no-shadow`, which our old pseudo-classes necessitated. *Please note:* I'm purposely not doing any `var` to `let`/`const` conversion here, since it's generally better to (if possible) do that automatically on e.g. a directory basis instead. --- src/core/worker.js | 57 ++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/src/core/worker.js b/src/core/worker.js index 1d1bd9acdbcd7..31bd828de52cf 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -37,39 +37,34 @@ import { MessageHandler } from "../shared/message_handler.js"; import { PDFWorkerStream } from "./worker_stream.js"; import { XRefParseException } from "./core_utils.js"; -var WorkerTask = (function WorkerTaskClosure() { - // eslint-disable-next-line no-shadow - function WorkerTask(name) { +class WorkerTask { + constructor(name) { this.name = name; this.terminated = false; this._capability = createPromiseCapability(); } - WorkerTask.prototype = { - get finished() { - return this._capability.promise; - }, - - finish() { - this._capability.resolve(); - }, + get finished() { + return this._capability.promise; + } - terminate() { - this.terminated = true; - }, + finish() { + this._capability.resolve(); + } - ensureNotTerminated() { - if (this.terminated) { - throw new Error("Worker task was terminated"); - } - }, - }; + terminate() { + this.terminated = true; + } - return WorkerTask; -})(); + ensureNotTerminated() { + if (this.terminated) { + throw new Error("Worker task was terminated"); + } + } +} -var WorkerMessageHandler = { - setup(handler, port) { +class WorkerMessageHandler { + static setup(handler, port) { var testMessageProcessed = false; handler.on("test", function wphSetupTest(data) { if (testMessageProcessed) { @@ -96,8 +91,9 @@ var WorkerMessageHandler = { handler.on("GetDocRequest", function wphSetupDoc(data) { return WorkerMessageHandler.createDocumentHandler(data, port); }); - }, - createDocumentHandler(docParams, port) { + } + + static createDocumentHandler(docParams, port) { // This context is actually holds references on pdfManager and handler, // until the latter is destroyed. var pdfManager; @@ -662,13 +658,14 @@ var WorkerMessageHandler = { docParams = null; // we don't need docParams anymore -- saving memory. }); return workerHandlerName; - }, - initializeFromPort(port) { + } + + static initializeFromPort(port) { var handler = new MessageHandler("worker", "main", port); WorkerMessageHandler.setup(handler, port); handler.send("ready", null); - }, -}; + } +} function isMessagePort(maybePort) { return (