Skip to content

[api-minor] Replace various getAll methods with iterators #19778

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
Apr 8, 2025

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented Apr 6, 2025

These getAll methods are not used anywhere within the PDF.js code-base, outside of tests, and were mostly added (speculatively) for third-party users.
To still allow access to the same data we instead introduce iterators on these classes, which (slightly) shortens the code and allows us to remove the objectFromMap helper function.

A summary of the changes in this patch:

  • Replace the getAll methods with iterators in the following classes: AnnotationStorage, Metadata, and OptionalContentGroup.

  • Change, and also re-name, AnnotationStorage.prototype.setAll into a test-only method since it's not used elsewhere.

  • Remove the Metadata.prototype.has method, since it's only used in tests and can be trivially replaced by calling Metadata.prototype.get and checking if the returned value is null.

@Snuffleupagus Snuffleupagus marked this pull request as ready for review April 6, 2025 17:58
@Snuffleupagus Snuffleupagus marked this pull request as draft April 6, 2025 19:33
@mozilla mozilla deleted a comment from moz-tools-bot Apr 6, 2025
@mozilla mozilla deleted a comment from moz-tools-bot Apr 6, 2025
@mozilla mozilla deleted a comment from moz-tools-bot Apr 6, 2025
@mozilla mozilla deleted a comment from moz-tools-bot Apr 6, 2025
These `getAll` methods are not used anywhere within the PDF.js code-base, outside of tests, and were mostly added (speculatively) for third-party users.
To still allow access to the same data we instead introduce iterators on these classes, which (slightly) shortens the code and allows us to remove the `objectFromMap` helper function.

A summary of the changes in this patch:
 - Replace the `getAll` methods with iterators in the following classes: `AnnotationStorage`, `Metadata`, and `OptionalContentGroup`.

 - Change, and also re-name, `AnnotationStorage.prototype.setAll` into a test-only method since it's not used elsewhere.

 - Remove the `Metadata.prototype.has` method, since it's only used in tests and can be trivially replaced by calling `Metadata.prototype.get` and checking if the returned value is `null`.
@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.241.84.105:8877/e9ae91cbee2b16e/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/ba1cf9c8fc9f781/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/e9ae91cbee2b16e/output.txt

Total script time: 29.89 mins

  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: Passed

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/ba1cf9c8fc9f781/output.txt

Total script time: 62.12 mins

  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: Passed

@Snuffleupagus Snuffleupagus marked this pull request as ready for review April 6, 2025 21:04
@nicolo-ribaudo
Copy link
Contributor

Question: how do you define api-minor and api-major? This PR is removing a method that you describe as "mostly used by consumers of the public API", which seems like the exact definition of an API breaking change.

@Snuffleupagus
Copy link
Collaborator Author

This PR is removing a method that you describe as "mostly used by consumers of the public API", which seems like the exact definition of an API breaking change.

Well, that's not exactly what the commit message says though: "[...] and were mostly added (speculatively) for third-party users."

It's impossible to know if users are actually depending on this, and for e.g. AnnotationStorage we've repeatedly stated that the data-format can/will change if deemed necessary since it's an internal implementation detail.
Hence users that depend of this functionality already has to, to some extent, handle breakage when updating and this is certainly not the worst change we've ever made in an api-minor patch since it's still possible to access the data albeit differently :-)

Copy link
Contributor

@calixteman calixteman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you.

@Snuffleupagus Snuffleupagus merged commit 22657e2 into mozilla:master Apr 8, 2025
9 checks passed
@Snuffleupagus Snuffleupagus deleted the replace-getAll branch April 8, 2025 15:26
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.

4 participants