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

Access navigator safely in the src/display/annotation_layer.js file #13801

Merged

Conversation

Snuffleupagus
Copy link
Collaborator

For code that's part of the core library, rather than e.g. the web/-folder, we should always be careful about directly accessing any DOM methods.
The navigator is one such structure, which shouldn't be assumed to always be available and we should thus check that it's actually present.[1]

Hence this patch re-factors the navigator.platform access, in the AnnotationLayer-code, to ensure that it's generally safe. Furthermore, to reduce unnecessary repeated string-matching to determine the current platform, we're now using a shadowed getter which is evaluated only once instead (at first access).


[1] Note e.g. the isSyncFontLoadingSupported getter, in the src/display/font_loader.js file.

For code that's part of the core library, rather than e.g. the `web/`-folder, we should always be careful about *directly* accessing any DOM methods.
The `navigator` is one such structure, which shouldn't be assumed to always be available and we should thus check that it's actually present.[1]

Hence this patch re-factors the `navigator.platform` access, in the `AnnotationLayer`-code, to ensure that it's generally safe. Furthermore, to reduce unnecessary repeated string-matching to determine the current platform, we're now using a shadowed getter which is evaluated only once instead (at first access).

---
[1] Note e.g. the `isSyncFontLoadingSupported` getter, in the `src/display/font_loader.js` file.
@Snuffleupagus
Copy link
Collaborator Author

/botio integrationtest

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_integrationtest from @Snuffleupagus received. Current queue size: 1

Live output at: http://54.67.70.0:8877/48f431ea4cc90c5/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_integrationtest from @Snuffleupagus received. Current queue size: 1

Live output at: http://3.101.106.178:8877/5def9d555853829/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/48f431ea4cc90c5/output.txt

Total script time: 4.48 mins

  • Integration Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://3.101.106.178:8877/5def9d555853829/output.txt

Total script time: 5.41 mins

  • Integration Tests: Passed

@timvandermeij timvandermeij merged commit e51cbe6 into mozilla:master Jul 27, 2021
@timvandermeij
Copy link
Contributor

Thank you for improving this!

@Snuffleupagus Snuffleupagus deleted the AnnotationLayer-check-navigator branch July 27, 2021 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants