mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
[api-minor] Only use Workers when postMessage
transfers are supported (PR 11123 follow-up)
Given that all modern browsers now support `postMessage` transfers, and have for years, it no longer seems necessary for the PDF.js library to support using Workers unless the `postMessage` transfers functionality is available. This patch is a follow-up to PR 11123, which made it impossible to *manually* disable `postMessage` transfers for performance reasons (since it increases memory usage), which hasn't caused any bug reports as far as I know.[1] Hence we'll now only support *proper* Worker implementations, with fully working `postMessage` transfers, and fallback to using "fake" Workers otherwise. --- [1] At the time of that PR we still "supported" IE, which is why this code was left intact.
This commit is contained in:
parent
9f4a2cf5ce
commit
6f22327e61
3 changed files with 9 additions and 41 deletions
|
@ -75,16 +75,9 @@ class WorkerMessageHandler {
|
|||
}
|
||||
testMessageProcessed = true;
|
||||
|
||||
// check if Uint8Array can be sent to worker
|
||||
if (!(data instanceof Uint8Array)) {
|
||||
handler.send("test", null);
|
||||
return;
|
||||
}
|
||||
// making sure postMessage transfers are working
|
||||
const supportTransfers = data[0] === 255;
|
||||
handler.postMessageTransfers = supportTransfers;
|
||||
|
||||
handler.send("test", { supportTransfers });
|
||||
// Ensure that `TypedArray`s can be sent to the worker,
|
||||
// and that `postMessage` transfers are supported.
|
||||
handler.send("test", data instanceof Uint8Array && data[0] === 255);
|
||||
});
|
||||
|
||||
handler.on("configure", function wphConfigure(data) {
|
||||
|
@ -156,10 +149,6 @@ class WorkerMessageHandler {
|
|||
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.
|
||||
handler.postMessageTransfers = docParams.postMessageTransfers;
|
||||
|
||||
function ensureNotTerminated() {
|
||||
if (terminated) {
|
||||
throw new Error("Worker was terminated");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue