From eef53347fef37838f6ed451c8b85a357dd32a263 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 5 Jun 2018 20:29:52 +0200 Subject: [PATCH] Ensure that the correct data is sent, with the `test` message, from the worker if typed arrays aren't properly supported With native typed array support now being mandatory in PDF.js, since version 2.0, this probably isn't a huge problem even though the current code seems wrong (it was changed in PR 6571). Note how in the `!(data instanceof Uint8Array)` case we're currently attempting to send `handler.send('test', 'main', false);` to the main-thread, which doesn't really make any sense since the signature of the method reads `send(actionName, data, transfers) {`. Hence the data that's *actually* being sent here is `'main'`, with `false` as the transferList, which just seems weird. On the main-thread, this means that we're in this case checking `data && data.supportTypedArray`, where `data` contains the string `'main'` rather than being falsy. Since a string doesn't have a `supportTypedArray` property, that check still fails as expected but it doesn't seem great nonetheless. --- src/core/worker.js | 2 +- src/display/api.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/worker.js b/src/core/worker.js index 45c8e33cc..567343864 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -335,7 +335,7 @@ var WorkerMessageHandler = { // check if Uint8Array can be sent to worker if (!(data instanceof Uint8Array)) { - handler.send('test', 'main', false); + handler.send('test', false); return; } // making sure postMessage transfers are working diff --git a/src/display/api.js b/src/display/api.js index ce3713afa..3bd0a60ee 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -1480,8 +1480,7 @@ var PDFWorker = (function PDFWorkerClosure() { terminateEarly(); return; // worker was destroyed } - var supportTypedArray = data && data.supportTypedArray; - if (supportTypedArray) { + if (data && data.supportTypedArray) { this._messageHandler = messageHandler; this._port = worker; this._webWorker = worker;