зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1650435: Add a testing function to expose some ICU configurations. r=jwalden
And add a test case to ensure we're using the latest tzdata version. Differential Revision: https://phabricator.services.mozilla.com/D82201
This commit is contained in:
Родитель
a33ac518b9
Коммит
2c6cfd41fa
|
@ -34,6 +34,7 @@
|
|||
#include "jsapi.h"
|
||||
#include "jsfriendapi.h"
|
||||
|
||||
#include "builtin/intl/CommonFunctions.h"
|
||||
#include "builtin/Promise.h"
|
||||
#include "builtin/SelfHostingDefines.h"
|
||||
#ifdef DEBUG
|
||||
|
@ -66,6 +67,13 @@
|
|||
#include "js/Vector.h"
|
||||
#include "js/Wrapper.h"
|
||||
#include "threading/CpuCount.h"
|
||||
#ifdef JS_HAS_INTL_API
|
||||
# include "unicode/ucal.h"
|
||||
# include "unicode/uchar.h"
|
||||
# include "unicode/uloc.h"
|
||||
# include "unicode/utypes.h"
|
||||
# include "unicode/uversion.h"
|
||||
#endif
|
||||
#include "util/StringBuffer.h"
|
||||
#include "util/Text.h"
|
||||
#include "vm/AsyncFunction.h"
|
||||
|
@ -5914,6 +5922,62 @@ static bool NumberToDouble(JSContext* cx, unsigned argc, Value* vp) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool GetICUOptions(JSContext* cx, unsigned argc, Value* vp) {
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
RootedObject info(cx, JS_NewPlainObject(cx));
|
||||
if (!info) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef JS_HAS_INTL_API
|
||||
RootedString str(cx);
|
||||
|
||||
str = NewStringCopyZ<CanGC>(cx, U_ICU_VERSION);
|
||||
if (!str || !JS_DefineProperty(cx, info, "version", str, JSPROP_ENUMERATE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
str = NewStringCopyZ<CanGC>(cx, U_UNICODE_VERSION);
|
||||
if (!str || !JS_DefineProperty(cx, info, "unicode", str, JSPROP_ENUMERATE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
str = NewStringCopyZ<CanGC>(cx, uloc_getDefault());
|
||||
if (!str || !JS_DefineProperty(cx, info, "locale", str, JSPROP_ENUMERATE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
const char* tzdataVersion = ucal_getTZDataVersion(&status);
|
||||
if (U_FAILURE(status)) {
|
||||
intl::ReportInternalError(cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
str = NewStringCopyZ<CanGC>(cx, tzdataVersion);
|
||||
if (!str || !JS_DefineProperty(cx, info, "tzdata", str, JSPROP_ENUMERATE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
str = intl::CallICU(cx, ucal_getDefaultTimeZone);
|
||||
if (!str || !JS_DefineProperty(cx, info, "timezone", str, JSPROP_ENUMERATE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
# ifndef U_HIDE_DRAFT_API
|
||||
str = intl::CallICU(cx, ucal_getHostTimeZone);
|
||||
if (!str ||
|
||||
!JS_DefineProperty(cx, info, "host-timezone", str, JSPROP_ENUMERATE)) {
|
||||
return false;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
args.rval().setObject(*info);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool PCCountProfiling_Start(JSContext* cx, unsigned argc, Value* vp) {
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
|
@ -6884,6 +6948,16 @@ gc::ZealModeHelpText),
|
|||
"numberToDouble(number)",
|
||||
" Return the input number as double-typed number."),
|
||||
|
||||
JS_FN_HELP("getICUOptions", GetICUOptions, 0, 0,
|
||||
"getICUOptions()",
|
||||
" Return an object describing the following ICU options.\n\n"
|
||||
" version: a string containing the ICU version number, e.g. '67.1'\n"
|
||||
" unicode: a string containing the Unicode version number, e.g. '13.0'\n"
|
||||
" locale: the ICU default locale, e.g. 'en_US'\n"
|
||||
" tzdata: a string containing the tzdata version number, e.g. '2020a'\n"
|
||||
" timezone: the ICU default time zone, e.g. 'America/Los_Angeles'\n"
|
||||
" host-timezone: the host time zone, e.g. 'America/Los_Angeles'"),
|
||||
|
||||
JS_FS_HELP_END
|
||||
};
|
||||
// clang-format on
|
||||
|
|
|
@ -2092,11 +2092,38 @@ def generateTzDataTestBackzoneLinks(tzdataDir, version, ignoreBackzone, testDir)
|
|||
)
|
||||
|
||||
|
||||
def generateTzDataTestVersion(tzdataDir, version, testDir):
|
||||
fileName = "timeZone_version.js"
|
||||
|
||||
with io.open(os.path.join(testDir, fileName), mode="w", encoding="utf-8", newline="") as f:
|
||||
println = partial(print, file=f)
|
||||
|
||||
println(u'// |reftest| skip-if(!this.hasOwnProperty("Intl"))')
|
||||
println(u"")
|
||||
println(generatedFileWarning)
|
||||
println(tzdataVersionComment.format(version))
|
||||
println(u"""const tzdata = "{0}";""".format(version))
|
||||
|
||||
println(u"""
|
||||
if (typeof getICUOptions === "undefined") {
|
||||
var getICUOptions = SpecialPowers.Cu.getJSTestingFunctions().getICUOptions;
|
||||
}
|
||||
|
||||
var options = getICUOptions();
|
||||
|
||||
assertEq(options.tzdata, tzdata);
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(0, 0, "ok");
|
||||
""")
|
||||
|
||||
|
||||
def generateTzDataTests(tzdataDir, version, ignoreBackzone, testDir):
|
||||
generateTzDataTestBackwardLinks(tzdataDir, version, ignoreBackzone, testDir)
|
||||
generateTzDataTestNotBackwardLinks(tzdataDir, version, ignoreBackzone, testDir)
|
||||
generateTzDataTestBackzone(tzdataDir, version, ignoreBackzone, testDir)
|
||||
generateTzDataTestBackzoneLinks(tzdataDir, version, ignoreBackzone, testDir)
|
||||
generateTzDataTestVersion(tzdataDir, version, testDir)
|
||||
|
||||
|
||||
def updateTzdata(topsrcdir, args):
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
// |reftest| skip-if(!this.hasOwnProperty("Intl"))
|
||||
|
||||
// Generated by make_intl_data.py. DO NOT EDIT.
|
||||
// tzdata version = 2020a
|
||||
const tzdata = "2020a";
|
||||
|
||||
if (typeof getICUOptions === "undefined") {
|
||||
var getICUOptions = SpecialPowers.Cu.getJSTestingFunctions().getICUOptions;
|
||||
}
|
||||
|
||||
var options = getICUOptions();
|
||||
|
||||
assertEq(options.tzdata, tzdata);
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(0, 0, "ok");
|
||||
|
Загрузка…
Ссылка в новой задаче