[api-minor] Remove support for synchronous event dispatching in LoopbackPort
#12999
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Please note: The
defer
parameter has been enabled by default ever since PR #9777 (in 2018), which first shipped in PDF.js release2.0.943
.With workers disabled, e.g. in Node.js environments, this has been used ever since without any problems reported[1].
The impetus for this change was that I happened to notice that if the
LoopbackPort
was used with synchronous event dispatching, we'd simply send that data as-is to the listeners. This created an inconsistency in the data returned from thepdf.worker.js
file, sincepostMessage
used with actual workers (or theLoopbackPort
withdefer = true
) will ignore/throw when encountering unclonable data.Originally my intention was simply to just call
cloneValue
regardless of the event dispatching used inLoopbackPort
, however looking at the use-cases (or lack thereof) of theLoopbackPort
it seemed reasonable to simply remove thedefer
parameter instead.This patch is tagged "[api-minor]" since the
LoopbackPort
is still exposed in the API, although I really hope that no third-party is using this (since disabling workers leads to bad performance).Finally, this patch changes a
forEach
loop tofor...of
and makes uses of optional changing in existing code.[1] As evident by the
npm test
command run by Github Actions, and previously by Travis.