Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert the code in src/core/worker.js to use ES6 classes #12004

Merged
merged 1 commit into from
Jun 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 27 additions & 30 deletions src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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 (
Expand Down