[Intl] Remove static dtors from Intl
Remove -Wexit-time-destructors warnings which triggered when global objects cause destructors to be run at exit time. Bug: v8:8257 Change-Id: I8407f1936cd6d13a2e30f55cfb4907a99ccca033 Reviewed-on: https://chromium-review.googlesource.com/c/1259863 Commit-Queue: Frank Tang <ftang@chromium.org> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Cr-Commit-Position: refs/heads/master@{#56388}
This commit is contained in:
parent
fb4d8c01af
commit
60b0bea81c
@ -41,7 +41,7 @@ class PatternMap {
|
||||
class PatternItem {
|
||||
public:
|
||||
PatternItem(const std::string property, std::vector<PatternMap> pairs,
|
||||
std::vector<const char*>* allowed_values)
|
||||
std::vector<const char*> allowed_values)
|
||||
: property(std::move(property)),
|
||||
pairs(std::move(pairs)),
|
||||
allowed_values(allowed_values) {}
|
||||
@ -51,25 +51,24 @@ class PatternItem {
|
||||
// It is important for the pattern in the pairs from longer one to shorter one
|
||||
// if the longer one contains substring of an shorter one.
|
||||
std::vector<PatternMap> pairs;
|
||||
std::vector<const char*>* allowed_values;
|
||||
std::vector<const char*> allowed_values;
|
||||
};
|
||||
|
||||
static const std::vector<PatternItem>& GetPatternItems() {
|
||||
static std::vector<const char*> kLongShort = {"long", "short"};
|
||||
static std::vector<const char*> kNarrowLongShort = {"narrow", "long",
|
||||
"short"};
|
||||
static std::vector<const char*> k2DigitNumeric = {"2-digit", "numeric"};
|
||||
static std::vector<const char*> kNarrowLongShort2DigitNumeric = {
|
||||
const std::vector<PatternItem> GetPatternItems() {
|
||||
const std::vector<const char*> kLongShort = {"long", "short"};
|
||||
const std::vector<const char*> kNarrowLongShort = {"narrow", "long", "short"};
|
||||
const std::vector<const char*> k2DigitNumeric = {"2-digit", "numeric"};
|
||||
const std::vector<const char*> kNarrowLongShort2DigitNumeric = {
|
||||
"narrow", "long", "short", "2-digit", "numeric"};
|
||||
static std::vector<PatternItem> kPatternItems = {
|
||||
const std::vector<PatternItem> kPatternItems = {
|
||||
PatternItem("weekday",
|
||||
{{"EEEEE", "narrow"}, {"EEEE", "long"}, {"EEE", "short"}},
|
||||
&kNarrowLongShort),
|
||||
kNarrowLongShort),
|
||||
PatternItem("era",
|
||||
{{"GGGGG", "narrow"}, {"GGGG", "long"}, {"GGG", "short"}},
|
||||
&kNarrowLongShort),
|
||||
kNarrowLongShort),
|
||||
PatternItem("year", {{"yy", "2-digit"}, {"y", "numeric"}},
|
||||
&k2DigitNumeric),
|
||||
k2DigitNumeric),
|
||||
// Sometimes we get L instead of M for month - standalone name.
|
||||
PatternItem("month",
|
||||
{{"MMMMM", "narrow"},
|
||||
@ -82,28 +81,27 @@ static const std::vector<PatternItem>& GetPatternItems() {
|
||||
{"LLL", "short"},
|
||||
{"LL", "2-digit"},
|
||||
{"L", "numeric"}},
|
||||
&kNarrowLongShort2DigitNumeric),
|
||||
PatternItem("day", {{"dd", "2-digit"}, {"d", "numeric"}},
|
||||
&k2DigitNumeric),
|
||||
kNarrowLongShort2DigitNumeric),
|
||||
PatternItem("day", {{"dd", "2-digit"}, {"d", "numeric"}}, k2DigitNumeric),
|
||||
PatternItem("hour",
|
||||
{{"HH", "2-digit"},
|
||||
{"H", "numeric"},
|
||||
{"hh", "2-digit"},
|
||||
{"h", "numeric"}},
|
||||
&k2DigitNumeric),
|
||||
k2DigitNumeric),
|
||||
PatternItem("minute", {{"mm", "2-digit"}, {"m", "numeric"}},
|
||||
&k2DigitNumeric),
|
||||
k2DigitNumeric),
|
||||
PatternItem("second", {{"ss", "2-digit"}, {"s", "numeric"}},
|
||||
&k2DigitNumeric),
|
||||
k2DigitNumeric),
|
||||
PatternItem("timeZoneName", {{"zzzz", "long"}, {"z", "short"}},
|
||||
&kLongShort)};
|
||||
kLongShort)};
|
||||
return kPatternItems;
|
||||
}
|
||||
|
||||
class PatternData {
|
||||
public:
|
||||
PatternData(const std::string property, std::vector<PatternMap> pairs,
|
||||
std::vector<const char*>* allowed_values)
|
||||
std::vector<const char*> allowed_values)
|
||||
: property(std::move(property)), allowed_values(allowed_values) {
|
||||
for (const auto& pair : pairs) {
|
||||
map.insert(std::make_pair(pair.value, pair.pattern));
|
||||
@ -113,7 +111,7 @@ class PatternData {
|
||||
|
||||
const std::string property;
|
||||
std::map<const std::string, const std::string> map;
|
||||
std::vector<const char*>* allowed_values;
|
||||
std::vector<const char*> allowed_values;
|
||||
};
|
||||
|
||||
enum HourOption {
|
||||
@ -122,7 +120,7 @@ enum HourOption {
|
||||
H_24,
|
||||
};
|
||||
|
||||
static const std::vector<PatternData> CreateCommonData() {
|
||||
const std::vector<PatternData> CreateCommonData() {
|
||||
std::vector<PatternData> build;
|
||||
for (const auto& item : GetPatternItems()) {
|
||||
if (item.property != "hour") {
|
||||
@ -133,20 +131,20 @@ static const std::vector<PatternData> CreateCommonData() {
|
||||
return build;
|
||||
}
|
||||
|
||||
static const std::vector<PatternData> CreateData(const char* digit2,
|
||||
const char* numeric) {
|
||||
static std::vector<const char*> k2DigitNumeric = {"2-digit", "numeric"};
|
||||
static const std::vector<PatternData> common = CreateCommonData();
|
||||
const std::vector<PatternData> CreateData(const char* digit2,
|
||||
const char* numeric) {
|
||||
const std::vector<const char*> k2DigitNumeric = {"2-digit", "numeric"};
|
||||
const std::vector<PatternData> common = CreateCommonData();
|
||||
std::vector<PatternData> build(common);
|
||||
build.push_back(PatternData(
|
||||
"hour", {{digit2, "2-digit"}, {numeric, "numeric"}}, &k2DigitNumeric));
|
||||
"hour", {{digit2, "2-digit"}, {numeric, "numeric"}}, k2DigitNumeric));
|
||||
return build;
|
||||
}
|
||||
|
||||
static const std::vector<PatternData>& GetPatternData(HourOption option) {
|
||||
static const std::vector<PatternData> data = CreateData("jj", "j");
|
||||
static const std::vector<PatternData> data_h12 = CreateData("hh", "h");
|
||||
static const std::vector<PatternData> data_h24 = CreateData("HH", "H");
|
||||
const std::vector<PatternData> GetPatternData(HourOption option) {
|
||||
const std::vector<PatternData> data = CreateData("jj", "j");
|
||||
const std::vector<PatternData> data_h12 = CreateData("hh", "h");
|
||||
const std::vector<PatternData> data_h24 = CreateData("HH", "H");
|
||||
switch (option) {
|
||||
case HourOption::H_12:
|
||||
return data_h12;
|
||||
@ -160,7 +158,7 @@ static const std::vector<PatternData>& GetPatternData(HourOption option) {
|
||||
void SetPropertyFromPattern(Isolate* isolate, const std::string& pattern,
|
||||
Handle<JSObject> options) {
|
||||
Factory* factory = isolate->factory();
|
||||
const std::vector<PatternItem>& items = GetPatternItems();
|
||||
const std::vector<PatternItem> items = GetPatternItems();
|
||||
for (const auto& item : items) {
|
||||
for (const auto& pair : item.pairs) {
|
||||
if (pattern.find(pair.pattern) != std::string::npos) {
|
||||
@ -410,7 +408,7 @@ Maybe<std::string> JSDateTimeFormat::OptionsToSkeleton(
|
||||
for (const auto& item : GetPatternData(hour_option)) {
|
||||
std::unique_ptr<char[]> input;
|
||||
Maybe<bool> maybe_get_option = Intl::GetStringOption(
|
||||
isolate, options, item.property.c_str(), *(item.allowed_values),
|
||||
isolate, options, item.property.c_str(), item.allowed_values,
|
||||
"Intl.DateTimeFormat", &input);
|
||||
MAYBE_RETURN(maybe_get_option, Nothing<std::string>());
|
||||
if (maybe_get_option.FromJust()) {
|
||||
@ -799,7 +797,7 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::Initialize(
|
||||
MAYBE_RETURN(maybe_found_matcher, Handle<JSDateTimeFormat>());
|
||||
|
||||
// 17. Let timeZone be ? Get(options, "timeZone").
|
||||
static std::vector<const char*> empty_values = {};
|
||||
std::vector<const char*> empty_values = {};
|
||||
std::unique_ptr<char[]> timezone = nullptr;
|
||||
Maybe<bool> maybe_timezone = Intl::GetStringOption(
|
||||
isolate, options, "timeZone", empty_values, kService, &timezone);
|
||||
|
@ -49,12 +49,12 @@ Maybe<bool> InsertOptionsIntoLocale(Isolate* isolate,
|
||||
CHECK(isolate);
|
||||
CHECK(icu_locale);
|
||||
|
||||
static std::vector<const char*> hour_cycle_values = {"h11", "h12", "h23",
|
||||
"h24"};
|
||||
static std::vector<const char*> case_first_values = {"upper", "lower",
|
||||
"false"};
|
||||
static std::vector<const char*> empty_values = {};
|
||||
static const std::array<OptionData, 6> kOptionToUnicodeTagMap = {
|
||||
const std::vector<const char*> hour_cycle_values = {"h11", "h12", "h23",
|
||||
"h24"};
|
||||
const std::vector<const char*> case_first_values = {"upper", "lower",
|
||||
"false"};
|
||||
const std::vector<const char*> empty_values = {};
|
||||
const std::array<OptionData, 6> kOptionToUnicodeTagMap = {
|
||||
{{"calendar", "ca", &empty_values, false},
|
||||
{"collation", "co", &empty_values, false},
|
||||
{"hourCycle", "hc", &hour_cycle_values, false},
|
||||
|
@ -272,8 +272,8 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::Initialize(
|
||||
// "percent", "currency" », "decimal").
|
||||
const char* service = "Intl.NumberFormat";
|
||||
std::unique_ptr<char[]> style_cstr;
|
||||
static std::vector<const char*> style_values = {"decimal", "percent",
|
||||
"currency"};
|
||||
const std::vector<const char*> style_values = {"decimal", "percent",
|
||||
"currency"};
|
||||
Maybe<bool> found_style = Intl::GetStringOption(
|
||||
isolate, options, "style", style_values, service, &style_cstr);
|
||||
MAYBE_RETURN(found_style, MaybeHandle<JSNumberFormat>());
|
||||
@ -293,7 +293,7 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::Initialize(
|
||||
// 14. Let currency be ? GetOption(options, "currency", "string", undefined,
|
||||
// undefined).
|
||||
std::unique_ptr<char[]> currency_cstr;
|
||||
static std::vector<const char*> empty_values = {};
|
||||
const std::vector<const char*> empty_values = {};
|
||||
Maybe<bool> found_currency = Intl::GetStringOption(
|
||||
isolate, options, "currency", empty_values, service, ¤cy_cstr);
|
||||
MAYBE_RETURN(found_currency, MaybeHandle<JSNumberFormat>());
|
||||
@ -335,8 +335,8 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::Initialize(
|
||||
// 18. Let currencyDisplay be ? GetOption(options, "currencyDisplay",
|
||||
// "string", « "code", "symbol", "name" », "symbol").
|
||||
std::unique_ptr<char[]> currency_display_cstr;
|
||||
static std::vector<const char*> currency_display_values = {"code", "name",
|
||||
"symbol"};
|
||||
const std::vector<const char*> currency_display_values = {"code", "name",
|
||||
"symbol"};
|
||||
Maybe<bool> found_currency_display = Intl::GetStringOption(
|
||||
isolate, options, "currencyDisplay", currency_display_values, service,
|
||||
¤cy_display_cstr);
|
||||
|
Loading…
Reference in New Issue
Block a user