Skip to content

[api-minor] Remove support for synchronous event dispatching in LoopbackPort #12999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2021

Conversation

Snuffleupagus
Copy link
Collaborator

Please note: The defer parameter has been enabled by default ever since PR #9777 (in 2018), which first shipped in PDF.js release 2.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 the pdf.worker.js file, since postMessage used with actual workers (or the LoopbackPort with defer = true) will ignore/throw when encountering unclonable data.
Originally my intention was simply to just call cloneValue regardless of the event dispatching used in LoopbackPort, however looking at the use-cases (or lack thereof) of the LoopbackPort it seemed reasonable to simply remove the defer 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 to for...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.

…backPort`

*Please note:* The `defer` parameter has been enabled by default ever since PR 9777 (in 2018), which first shipped in PDF.js release `2.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 the `pdf.worker.js` file, since `postMessage` used with *actual* workers (or the `LoopbackPort` with `defer = true`) will ignore/throw when encountering unclonable data.
Originally my intention was simply to just call `cloneValue` regardless of the event dispatching used in `LoopbackPort`, however looking at the use-cases (or lack thereof) of the `LoopbackPort` it seemed reasonable to simply remove the `defer` 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 to `for...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.
@Snuffleupagus
Copy link
Collaborator Author

/botio unittest

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_unittest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/770e36c7dfed554/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_unittest from @Snuffleupagus received. Current queue size: 0

Live output at: http://3.101.106.178:8877/5020bb87c38e235/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/770e36c7dfed554/output.txt

Total script time: 3.63 mins

  • Unit Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://3.101.106.178:8877/5020bb87c38e235/output.txt

Total script time: 5.27 mins

  • Unit Tests: Passed

@timvandermeij timvandermeij merged commit 77862bd into mozilla:master Feb 17, 2021
@timvandermeij
Copy link
Contributor

I also don't see a particular good use case for this. Let's remove it; thanks!

@Snuffleupagus Snuffleupagus deleted the LoopbackPort-rm-sync branch February 17, 2021 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants