Closed Bug 1602940 Opened 4 years ago Closed 3 years ago

Expose nsIUUIDGenerator on Services.jsm

Categories

(Toolkit :: General, task, P3)

task

Tracking

()

RESOLVED FIXED
94 Branch
Tracking Status
firefox94 --- fixed

People

(Reporter: Gijs, Assigned: standard8)

References

Details

Attachments

(5 files)

As per summary. Services.uuid seems like it should work.

Priority: -- → P3
See Also: → 1603144
Assignee: nobody → ato
Status: NEW → ASSIGNED
Priority: P3 → P1
Whiteboard: [puppeteer-beta-reserve]

By adding a shorthand for nsIUUIDGenerator to Services.jsm we can
avoid a lot of boilerplate code for a frequently used service.

Using nsIUUIDGenerator from JavaScript today normally looks something
like this:

const uuidGen = Cc["mozilla.org/uuid-generator;1"]
      .getService(Ci.nsIUUIDGenerator);
    uuidGen.generateUUID();

Which with this patch now be shortened to:

Services.uuid.generateUUID();

By adding a new generate() method returning a string directly from
nsIUUIDGenerator we are able to avoid many cumbersome string coercions.

In JavaScript, string representations of UUIDs are more often than
not the requirement. This is usually to ease serialisation.

We may want to consider renaming nsIUUIDGenerator.generateUUID()
in the future to generateIDPtr() or similar, but this would require
a larger refactoring due to existing usage. It would be advisable
to make JS usage move to generate() first, before attempting a
rewrite of the C++ consumers.

Whiteboard: [puppeteer-beta-reserve] → [puppeteer-beta-mvp]
Whiteboard: [puppeteer-beta-mvp] → [puppeteer-beta-reserve]

That shouldn't actually block beta.

Assignee: ato → nobody
Status: ASSIGNED → NEW
Priority: P1 → P3
Whiteboard: [puppeteer-beta-reserve]
Assignee: nobody → standard8
Status: NEW → ASSIGNED

This also adds a commented out option for automatically fixing use-services in the ESLint rule. This cannot be enabled at the moment as it needs special treatment for chrome tests.

Pushed by mbanner@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/b9f9c4e0bb1d
Add nsIUUIDGenerator to the Javascript Services object. r=Gijs
https://hg.mozilla.org/integration/autoland/rev/d0ec1bb4c138
Automated replacements to use Services.uuid. r=Gijs,necko-reviewers,preferences-reviewers,kershaw
https://hg.mozilla.org/integration/autoland/rev/1ffad363c97e
Manual fixes to fix issues in files. r=Gijs,necko-reviewers,rpl,kershaw
Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/7855fef22513
fix Thunderbird consumers of nsIUUIDGenerator which is now in Services.jsm. rs=eslint
No longer blocks: 1603144
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: