Closed Bug 1878450 Opened 1 year ago Closed 1 year ago

Oversight with syncThrobberAnimations possibly trying to reduce an empty array

Categories

(Firefox :: Tabbed Browser, defect, P1)

defect

Tracking

()

RESOLVED FIXED
124 Branch
Tracking Status
firefox124 --- fixed

People

(Reporter: twisniewski, Assigned: sfoster)

References

Details

Attachments

(1 file)

I was just investigating this stray test-failure:

[task 2024-01-11T18:38:42.775Z] 18:38:42     INFO - TEST-UNEXPECTED-FAIL | browser/components/reportbrokensite/test/browser/browser_keyboard_navigation.js | uncaught exception - TypeError: reduce of empty array with no initial value at syncThrobberAnimations/<@chrome://browser/content/tabbrowser.js:792:12

Indeed, the related code might end up with an empty array and thus fail when it reaches the reduce:

syncThrobberAnimations(aTab) {
 // snip for brevity
 const animations = Array.from(
          aTab.container.getElementsByTagName("tab")
        )
          .filter(tab => tab.hasAttribute("busy"))
          .map(tab => {
            const throbber = tab.throbber;
            return throbber ? throbber.getAnimations({ subtree: true }) : [];
          })
          .reduce((a, b) => a.concat(b), [])

This seems like something worth fixing.

See Also: → 1867132

Cards on the table, I'm not the best with functional programming nor very familiar with reduce. I can't seem to reproduce the specific TypeError (though I only tried a few times):

[1].filter(x => x > 1).reduce((a,b) => a.concat(b), []);

At any rate, we should probably just be using .flat here instead of any fancy reduce stuff here, which (at least in my books) makes this less readable... I think that'll help sidestep this error condition.

sfoster, do you have a moment to try that? I'm happy to review it.

Flags: needinfo?(sfoster)

Yeah I'll put together a patch.

Assignee: nobody → sfoster
Severity: -- → S3
Status: NEW → ASSIGNED
Depends on: 1869928
Flags: needinfo?(sfoster)
Priority: -- → P1
Pushed by sfoster@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/dd2cbed14b68 Use flatMap when compiling the list of animations in syncThrobberAnimations. r=mconley,tabbrowser-reviewers
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 124 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: