Skip to content

[api-minor] Convert getJSActions to return data in a Map - #21664

Merged
Snuffleupagus merged 1 commit into
mozilla:masterfrom
Snuffleupagus:getJSActions-api
Jul 31, 2026
Merged

[api-minor] Convert getJSActions to return data in a Map#21664
Snuffleupagus merged 1 commit into
mozilla:masterfrom
Snuffleupagus:getJSActions-api

Conversation

@Snuffleupagus

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.

Note also how in the scripting-implementation the actions were already converted into a Map, via the createActionsMap helper.
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 unfortunately JSON.stringify() doesn't support Maps. Hence we convert Maps to Objects, via a replacer function, since the existing createActionsMap usage will convert the actions-Objects back to Maps.

@codecov-commenter

codecov-commenter commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.96%. Comparing base (73707b6) to head (803c9d7).

Files with missing lines Patch % Lines
src/display/annotation_layer.js 90.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #21664   +/-   ##
=======================================
  Coverage   89.96%   89.96%           
=======================================
  Files         263      263           
  Lines       66886    66890    +4     
=======================================
+ Hits        60171    60179    +8     
+ Misses       6715     6711    -4     
Flag Coverage Δ
browsertest 66.54% <52.00%> (+0.01%) ⬆️
fonttest 9.04% <0.00%> (ø)
integrationtest 69.34% <96.42%> (+0.01%) ⬆️
unittest 57.57% <50.00%> (+<0.01%) ⬆️
unittestcli 56.51% <44.00%> (-0.01%) ⬇️

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.

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.

Note also how in the scripting-implementation the `actions` were already converted into a Map, via the `createActionsMap` helper.
In the Firefox PDF Viewer sending `Map`s 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 unfortunately `JSON.stringify()` doesn't support Maps. Hence we convert Maps to Objects, via a [`replacer` function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#replacer), since the existing `createActionsMap` usage will convert the actions-Objects back to Maps.
@Snuffleupagus

Copy link
Copy Markdown
Collaborator Author

/botio browsertest

@Snuffleupagus
Snuffleupagus marked this pull request as ready for review July 30, 2026 14:30
@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/50b1eccdace79dc/output.txt

@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/6b92c54280df5bc/output.txt

@Snuffleupagus
Snuffleupagus requested a review from calixteman July 30, 2026 14:34
@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/50b1eccdace79dc/output.txt

Total script time: 18.24 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/6b92c54280df5bc/output.txt

Total script time: 24.07 mins

  • Regression tests: Passed

@timvandermeij timvandermeij left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good; thank you!

@Snuffleupagus
Snuffleupagus merged commit ce4ff55 into mozilla:master Jul 31, 2026
21 checks passed
@Snuffleupagus
Snuffleupagus deleted the getJSActions-api branch July 31, 2026 09:29
@Snuffleupagus
Snuffleupagus removed the request for review from calixteman July 31, 2026 09:29
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