mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 17:30:09 +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
|
@ -439,7 +439,6 @@ function getDocument(src) {
|
|||
workerId,
|
||||
worker.port
|
||||
);
|
||||
messageHandler.postMessageTransfers = worker.postMessageTransfers;
|
||||
const transport = new WorkerTransport(
|
||||
messageHandler,
|
||||
task,
|
||||
|
@ -498,7 +497,6 @@ async function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
|
|||
},
|
||||
maxImageSize: source.maxImageSize,
|
||||
disableFontFace: source.disableFontFace,
|
||||
postMessageTransfers: worker.postMessageTransfers,
|
||||
docBaseUrl: source.docBaseUrl,
|
||||
ignoreErrors: source.ignoreErrors,
|
||||
isEvalSupported: source.isEvalSupported,
|
||||
|
@ -2079,7 +2077,6 @@ class PDFWorker {
|
|||
|
||||
this.name = name;
|
||||
this.destroyed = false;
|
||||
this.postMessageTransfers = true;
|
||||
this.verbosity = verbosity;
|
||||
|
||||
this._readyCapability = createPromiseCapability();
|
||||
|
@ -2188,13 +2185,10 @@ class PDFWorker {
|
|||
return; // worker was destroyed
|
||||
}
|
||||
if (data) {
|
||||
// supportTypedArray
|
||||
this._messageHandler = messageHandler;
|
||||
this._port = worker;
|
||||
this._webWorker = worker;
|
||||
if (!data.supportTransfers) {
|
||||
this.postMessageTransfers = false;
|
||||
}
|
||||
|
||||
this._readyCapability.resolve();
|
||||
// Send global setting, e.g. verbosity level.
|
||||
messageHandler.send("configure", {
|
||||
|
@ -2222,7 +2216,7 @@ class PDFWorker {
|
|||
});
|
||||
|
||||
const sendTest = () => {
|
||||
const testObj = new Uint8Array([this.postMessageTransfers ? 255 : 0]);
|
||||
const testObj = new Uint8Array([255]);
|
||||
// Some versions of Opera throw a DATA_CLONE_ERR on serializing the
|
||||
// typed array. Also, checking if we can use transfers.
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue