Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

nsIUUIDGenerator

This interface can be used to generate an ID that can be considered globally unique, often referred to as a UUID or GUID.
1.0
37.0.1
Introduced
Gecko 1.8.1
Inherits from: nsISupports Last changed in Gecko 1.8.1 (Firefox 2 / Thunderbird 2 / SeaMonkey 1.1)

Implemented by @mozilla.org/uuid-generator; as a service:

var uuidGenerator = Components.classes["@mozilla.org/uuid-generator;1"]
                    .getService(Components.interfaces.nsIUUIDGenerator);

Method overview

nsIDPtr generateUUID();
void generateUUIDInPlace(in nsNonConstIDPtr id); Native code only!

Methods

generateUUID()

Obtains a new UUID using appropriate platform-specific methods to obtain a nsID that can be considered to be globally unique.

nsIDPtr generateUUID();
Parameters

None.

Return value

This method returns a nsIDPtr containing a unique ID.

Exceptions thrown
NS_ERROR_FAILURE
If a UUID cannot be generated (for example if an underlying source of randomness is not available)

Native code only!

generateUUIDInPlace

Obtain a new UUID like the generateUUID() method, but place it in the provided nsID pointer instead of allocating a new nsID.

void generateUUIDInPlace(
  in nsNonConstIDPtr id
);
Parameters
id
An existing nsID pointer where the UUID will be stored.
Exceptions thrown
NS_ERROR_FAILURE
If a UUID cannot be generated (for example if an underlying source of randomness is not available)

Example

Generating a UUID

var uuidGenerator = Components.classes["@mozilla.org/uuid-generator;1"]
                    .getService(Components.interfaces.nsIUUIDGenerator);
var uuid = uuidGenerator.generateUUID();
var uuidString = uuid.toString();

Document Tags and Contributors

 Contributors to this page: Sheppy, xera1965, trevorh, Nickolay, Ted_Mielczarek
 Last updated by: Sheppy,