Open Bug 2052621 Opened 7 days ago Updated 7 days ago

Consinder converting ActionsResult from a class to a plain object + typedef

Categories

(Firefox :: Address Bar, task)

task

Tracking

()

People

(Reporter: dao, Unassigned)

References

(Blocks 1 open bug)

Details

(Whiteboard: [sng][mcab-hnt])

Attachments

(1 file)

Follow-up to bug 2052554 (D310306), addressing review comment https://phabricator.services.mozilla.com/D310306#10767851.

ActionsResult (browser/components/urlbar/ActionsProvider.sys.mjs) has no methods and its instances are never deserialized, so modeling it as a class is confusing. mbeier suggested using a plain object and converting the class definition to a TypeScript typedef.

Proposed change:

  • Replace the ActionsResult class with @typedef {object} ActionsResult -- providerName and key required, l10nId/l10nArgs/icon/dataset/engine optional.
  • Have the producers (ActionsProviderTabGroups, ActionsProviderQuickActions, ActionsProviderContextualSearch) build plain object literals typed via /** @type {ActionsResult} */ with a JSDoc @import, dropping the runtime import.

Required-ness is then enforced statically by tsc (the urlbar tsconfig.json has checkJs + strict), replacing the constructor's runtime throw.

Tradeoff: the class currently calls Object.freeze(this) so each result is read-only (matching the original getter-only fields). A plain object literal is mutable, so this conversion drops that read-only guarantee. In practice the results are built once and only read, so it's likely fine, but if immutability is still wanted it can be reinstated by freezing the literal.

Whiteboard: [sng][mcab-hnt]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: