Skip to content

Add scripts correctly in Field.prototype.setAction (PR 12569 follow-up) - #21691

Merged
Snuffleupagus merged 1 commit into
mozilla:masterfrom
Snuffleupagus:Field-setAction-Map
Aug 2, 2026
Merged

Add scripts correctly in Field.prototype.setAction (PR 12569 follow-up)#21691
Snuffleupagus merged 1 commit into
mozilla:masterfrom
Snuffleupagus:Field-setAction-Map

Conversation

@Snuffleupagus

Copy link
Copy Markdown
Collaborator

In PR #12569 the _actions class-field was changed from an Object into a Map, with most of the code updated to reflect that.
However, in the setAction method it's still treated as an Object which means that any added script will simply be ignored. Most likely that part of the scripting-implementation isn't being used, since this code has been "wrong" for close to six years now.

Note: This was found by code inspection, and I unfortunately don't have a test-case that fails without it.

@codecov-commenter

codecov-commenter commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.00%. Comparing base (d0779c4) to head (1f9fbc7).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #21691   +/-   ##
=======================================
  Coverage   90.00%   90.00%           
=======================================
  Files         263      263           
  Lines       66861    66861           
=======================================
  Hits        60178    60178           
  Misses       6683     6683           
Flag Coverage Δ
browsertest 66.54% <ø> (+0.01%) ⬆️
fonttest 9.04% <ø> (ø)
integrationtest 69.35% <ø> (-0.01%) ⬇️
unittest 57.84% <ø> (+0.01%) ⬆️
unittestcli 56.57% <ø> (+<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.

@Snuffleupagus
Snuffleupagus marked this pull request as ready for review August 2, 2026 16:08

@calixteman calixteman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Thank you.

@calixteman

Copy link
Copy Markdown
Contributor

You can add a this test:

diff --git a/test/unit/scripting_spec.js b/test/unit/scripting_spec.js
index 3e7b133ce..22eacaa9d 100644
--- a/test/unit/scripting_spec.js
+++ b/test/unit/scripting_spec.js
@@ -363,6 +363,80 @@ describe("Scripting", function () {
       });
     });

+    it("should trigger an event added with setAction", async () => {
+      const refId = getId();
+      const data = {
+        objects: {
+          field: [
+            {
+              id: refId,
+              value: "",
+              actions: {},
+              type: "text",
+            },
+          ],
+        },
+        appInfo: { language: "en-US", platform: "Linux x86_64" },
+        calculationOrder: [],
+      };
+      sandbox.createSandbox(data);
+
+      await myeval(
+        `(this.getField("field").setAction("test", 'event.source.value = "abc";'), 0)`
+      );
+
+      await sandbox.dispatchEventInSandbox({
+        id: refId,
+        value: "",
+        name: "test",
+        willCommit: true,
+      });
+
+      expect(send_queue.has(refId)).toBeTrue();
+      expect(send_queue.get(refId)).toEqual({
+        id: refId,
+        value: "abc",
+      });
+    });
+
+    it("should trigger an event appended with setAction", async () => {
+      const refId = getId();
+      const data = {
+        objects: {
+          field: [
+            {
+              id: refId,
+              value: "",
+              actions: {
+                test: [`event.source.value = "a";`],
+              },
+              type: "text",
+            },
+          ],
+        },
+        appInfo: { language: "en-US", platform: "Linux x86_64" },
+        calculationOrder: [],
+      };
+      sandbox.createSandbox(data);
+
+      await myeval(
+        `(this.getField("field").setAction("test", 'event.source.value += "b";'), 0)`
+      );
+
+      await sandbox.dispatchEventInSandbox({
+        id: refId,
+        value: "",
+        name: "test",
+        willCommit: true,
+      });
+
+      expect(send_queue.has(refId)).toBeTrue();
+      expect(send_queue.get(refId)).toEqual({
+        id: refId,
+        value: "ab",
+      });
+    });
+
     it("should trigger a Keystroke event and invalidate it", async () => {
       const refId = getId();
       const data = {

…-up)

In PR 12569 the `_actions` class-field was changed from an Object into a Map, with *most* of the code updated to reflect that.
However, in the `setAction` method it's still treated as an Object which means that any added script will simply be ignored. Most likely that part of the scripting-implementation isn't being used, since this code has been "wrong" for close to six years now.
@Snuffleupagus

Copy link
Copy Markdown
Collaborator Author

You can add a this test:
[...]

Great, thank you!

@Snuffleupagus
Snuffleupagus merged commit 923d48e into mozilla:master Aug 2, 2026
20 of 21 checks passed
@Snuffleupagus
Snuffleupagus deleted the Field-setAction-Map branch August 2, 2026 19:24
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