зеркало из https://github.com/mozilla/gecko-dev.git
Bug 806591 - Add CommonUtils.generateUUID utility function; r=rnewman
This commit is contained in:
Родитель
d5505fd697
Коммит
c054a5ad9d
|
@ -0,0 +1,12 @@
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
function run_test() {
|
||||||
|
let uuid = CommonUtils.generateUUID();
|
||||||
|
do_check_eq(uuid.length, 36);
|
||||||
|
do_check_eq(uuid[8], "-");
|
||||||
|
|
||||||
|
run_next_test();
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ tail =
|
||||||
[test_utils_namedTimer.js]
|
[test_utils_namedTimer.js]
|
||||||
[test_utils_stackTrace.js]
|
[test_utils_stackTrace.js]
|
||||||
[test_utils_utf8.js]
|
[test_utils_utf8.js]
|
||||||
|
[test_utils_uuid.js]
|
||||||
|
|
||||||
[test_aitc_server.js]
|
[test_aitc_server.js]
|
||||||
[test_async_chain.js]
|
[test_async_chain.js]
|
||||||
|
|
|
@ -467,6 +467,22 @@ this.CommonUtils = {
|
||||||
|
|
||||||
return new BinaryInputStream(stream).readBytes(count);
|
return new BinaryInputStream(stream).readBytes(count);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a new UUID using nsIUUIDGenerator.
|
||||||
|
*
|
||||||
|
* Example value: "1e00a2e2-1570-443e-bf5e-000354124234"
|
||||||
|
*
|
||||||
|
* @return string A hex-formatted UUID string.
|
||||||
|
*/
|
||||||
|
generateUUID: function generateUUID() {
|
||||||
|
let uuid = Cc["@mozilla.org/uuid-generator;1"]
|
||||||
|
.getService(Ci.nsIUUIDGenerator)
|
||||||
|
.generateUUID()
|
||||||
|
.toString();
|
||||||
|
|
||||||
|
return uuid.substring(1, uuid.length - 1);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
XPCOMUtils.defineLazyGetter(CommonUtils, "_utf8Converter", function() {
|
XPCOMUtils.defineLazyGetter(CommonUtils, "_utf8Converter", function() {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче