Skip to content

[api-minor] Convert getFieldObjects to return data in a Map - #21671

Merged
timvandermeij merged 2 commits into
mozilla:masterfrom
Snuffleupagus:getFieldObjects-Map
Aug 2, 2026
Merged

[api-minor] Convert getFieldObjects to return data in a Map#21671
timvandermeij merged 2 commits into
mozilla:masterfrom
Snuffleupagus:getFieldObjects-Map

Conversation

@Snuffleupagus

@Snuffleupagus Snuffleupagus commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Compared to regular Objects there's a number of advantages to using Maps:

  • They support proper iteration.
  • They have a simple way to check for the existence of data.
  • They have a simple/efficient way to check the number of elements.

If this functionality was added today, I cannot imagine that we'd choose an Object for this data.

In the Firefox PDF Viewer sending Maps to the scripting-implementation should be fine, since it uses the browser Cu.cloneInto functionality; see https://searchfox.org/firefox-main/source/toolkit/components/pdfjs/content/PdfSandbox.sys.mjs
However with QuickJS, used by the GENERIC viewer, all data needs to be stringified and Maps are converted into regular Objects (see also PR #21664). Hence the objects property, in the scripting-implementation, is converted back into a Map using the (renamed) createMap helper function.


Smaller diff with https://github.com/mozilla/pdf.js/pull/21671/changes?w=1

@codecov-commenter

codecov-commenter commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.00%. Comparing base (7590ad5) to head (8871631).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21671      +/-   ##
==========================================
- Coverage   90.00%   90.00%   -0.01%     
==========================================
  Files         263      263              
  Lines       66861    66861              
==========================================
- Hits        60177    60176       -1     
- Misses       6684     6685       +1     
Flag Coverage Δ
browsertest 66.52% <33.33%> (+<0.01%) ⬆️
fonttest 9.04% <ø> (ø)
integrationtest 69.35% <100.00%> (+<0.01%) ⬆️
unittest 57.83% <44.44%> (-0.01%) ⬇️
unittestcli 56.56% <44.44%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Snuffleupagus

Copy link
Copy Markdown
Collaborator Author

/botio browsertest

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/5d841a3b74051e1/output.txt

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Received

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

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

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Success

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

Total script time: 17.98 mins

  • Regression tests: Passed

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/5d841a3b74051e1/output.txt

Total script time: 23.42 mins

  • Regression tests: Passed

Compared to regular Objects there's a number of advantages to using Maps:
 - They support proper iteration.
 - They have a simple way to check for the existence of data.
 - They have a simple/efficient way to check the number of elements.

If this functionality was added today, I cannot imagine that we'd choose an Object for this data.

In the Firefox PDF Viewer sending Maps to the scripting-implementation should be fine, since it uses the browser `Cu.cloneInto` functionality; see https://searchfox.org/firefox-main/source/toolkit/components/pdfjs/content/PdfSandbox.sys.mjs
However with QuickJS, used by the GENERIC viewer, all data needs to be stringified and Maps are converted into regular Objects (see also PR 21664). Hence the `objects` property, in the scripting-implementation, is converted back into a Map using the (renamed) `createMap` helper function.
@timvandermeij

Copy link
Copy Markdown
Collaborator

Nice work; thanks!

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