[src/display/api.js] Simplify the sendTest function, used with Worker initialization (PR 14291 follow-up)

Given that we now only use Workers when `postMessage` transfers are supported, there's really no point in trying to send a "test" message *without* transfers present.
Hence, if `postMessage` transfers are not supported by the browser, we'll now fallback to "fake" Workers immediately instead. The comment about Opera is also removed, since it was originally added back in PR 983 and mentions Opera `11.60` [which was released in 2011](https://en.wikipedia.org/wiki/History_of_the_Opera_web_browser#Version_11).
This commit is contained in:
Jonas Jenwald 2022-03-16 13:04:47 +01:00
parent d5c9be341d
commit be2b1d5d2a
2 changed files with 5 additions and 13 deletions

View File

@ -75,9 +75,8 @@ class WorkerMessageHandler {
} }
testMessageProcessed = true; testMessageProcessed = true;
// Ensure that `TypedArray`s can be sent to the worker, // Ensure that `TypedArray`s can be sent to the worker.
// and that `postMessage` transfers are supported. handler.send("test", data instanceof Uint8Array);
handler.send("test", data instanceof Uint8Array && data[0] === 255);
}); });
handler.on("configure", function wphConfigure(data) { handler.on("configure", function wphConfigure(data) {

View File

@ -2167,16 +2167,9 @@ class PDFWorker {
}); });
const sendTest = () => { const sendTest = () => {
const testObj = new Uint8Array([255]); const testObj = new Uint8Array();
// Some versions of Opera throw a DATA_CLONE_ERR on serializing the // Ensure that we can use `postMessage` transfers.
// typed array. Also, checking if we can use transfers.
try {
messageHandler.send("test", testObj, [testObj.buffer]); messageHandler.send("test", testObj, [testObj.buffer]);
} catch (ex) {
warn("Cannot use postMessage transfers.");
testObj[0] = 0;
messageHandler.send("test", testObj);
}
}; };
// It might take time for the worker to initialize. We will try to send // It might take time for the worker to initialize. We will try to send