Skip to content
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

Modernize the FirefoxCom.request method #12801

Merged

Conversation

Snuffleupagus
Copy link
Collaborator

Please note: I've tested this patch in a local Firefox build, to ensure that I didn't break anything here :-)

  • Use the once: true option, rather than manually removing the "pdf.js.response" event listener in FirefoxCom.request

    When this code was originally added, the once option didn't exist yet.

  • Use remove, rather than removeChild, when removing the temporary Text nodes used in FirefoxCom

    This is the "modern" way of removing a node from the DOM, which has the benefit of being a lot shorter and more concise.

    Also, this patch removes the return statement from the "pdf.js.response" event listener, since it's always undefined, given that none of the callback-functions used here ever return anything (and don't need to either). Generally speaking, returning a value from an event listener isn't normally necessary either.

  • Ensure that the "pdf.js.response" event listener, in FirefoxCom.request, actually applies to the current Text node

    Given that the event listener is registered on the document, there could in theory be more than one of these listeners present at any one time.
    In practice this doesn't currently happen, since all of the actions invoked in PdfStreamConverter.jsm are synchronous methods. However, there's no guarantee that this will always be the case, and it's easy enough to prevent any future issues here by simply registering the "pdf.js.response" event listener on the Text node instead. This works since, as can be seen in PdfStreamConverter.jsm, the event is dispatched on the element itself rather than the document.

…s.response" event listener in `FirefoxCom.request`

When this code was originally added, the `once` option didn't exist yet.
…`Text` nodes used in `FirefoxCom`

This is the "modern" way of removing a node from the DOM, which has the benefit of being a lot shorter and more concise.

Also, this patch removes the `return` statement from the "pdf.js.response" event listener, since it's always `undefined`, given that none of the `callback`-functions used here ever return anything (and don't need to either). Generally speaking, returning a value from an event listener isn't normally necessary either.
…est`, actually applies to the current `Text` node

Given that the event listener is registered on the document, there could in *theory* be more than one of these listeners present at any one time.
In practice this doesn't currently happen, since all of the `actions` invoked in [`PdfStreamConverter.jsm`](https://searchfox.org/mozilla-central/rev/bfbacfb6a4efd98247e83d3305e912ca4f7e106a/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#933-952) are *synchronous* methods. However, there's no guarantee that this will always be the case, and it's easy enough to prevent any future issues here by simply registering the "pdf.js.response" event listener on the `Text` node instead. This works since, as can be seen in [`PdfStreamConverter.jsm`](https://searchfox.org/mozilla-central/rev/bfbacfb6a4efd98247e83d3305e912ca4f7e106a/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#919,943), the event is dispatched on the element itself rather than the document.
@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

pdfjsbot commented Jan 1, 2021

From: Bot.io (Linux m4)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/ef9de911740ccd0/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jan 1, 2021

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/ef9de911740ccd0/output.txt

Total script time: 4.16 mins

Published

@timvandermeij timvandermeij merged commit 0432154 into mozilla:master Jan 1, 2021
@timvandermeij
Copy link
Contributor

Looks good. Thank you!

@Snuffleupagus Snuffleupagus deleted the FirefoxCom-document-listener branch January 1, 2021 13:17
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