[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:
Frank Tang 2018-10-04 11:34:55 -07:00 committed by Commit Bot
parent fb4d8c01af
commit 60b0bea81c
3 changed files with 43 additions and 45 deletions

View File

@ -41,7 +41,7 @@ class PatternMap {
class PatternItem { class PatternItem {
public: public:
PatternItem(const std::string property, std::vector<PatternMap> pairs, 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)), : property(std::move(property)),
pairs(std::move(pairs)), pairs(std::move(pairs)),
allowed_values(allowed_values) {} 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 // 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. // if the longer one contains substring of an shorter one.
std::vector<PatternMap> pairs; std::vector<PatternMap> pairs;
std::vector<const char*>* allowed_values; std::vector<const char*> allowed_values;
}; };
static const std::vector<PatternItem>& GetPatternItems() { const std::vector<PatternItem> GetPatternItems() {
static std::vector<const char*> kLongShort = {"long", "short"}; const std::vector<const char*> kLongShort = {"long", "short"};
static std::vector<const char*> kNarrowLongShort = {"narrow", "long", const std::vector<const char*> kNarrowLongShort = {"narrow", "long", "short"};
"short"}; const std::vector<const char*> k2DigitNumeric = {"2-digit", "numeric"};
static std::vector<const char*> k2DigitNumeric = {"2-digit", "numeric"}; const std::vector<const char*> kNarrowLongShort2DigitNumeric = {
static std::vector<const char*> kNarrowLongShort2DigitNumeric = {
"narrow", "long", "short", "2-digit", "numeric"}; "narrow", "long", "short", "2-digit", "numeric"};
static std::vector<PatternItem> kPatternItems = { const std::vector<PatternItem> kPatternItems = {
PatternItem("weekday", PatternItem("weekday",
{{"EEEEE", "narrow"}, {"EEEE", "long"}, {"EEE", "short"}}, {{"EEEEE", "narrow"}, {"EEEE", "long"}, {"EEE", "short"}},
&kNarrowLongShort), kNarrowLongShort),
PatternItem("era", PatternItem("era",
{{"GGGGG", "narrow"}, {"GGGG", "long"}, {"GGG", "short"}}, {{"GGGGG", "narrow"}, {"GGGG", "long"}, {"GGG", "short"}},
&kNarrowLongShort), kNarrowLongShort),
PatternItem("year", {{"yy", "2-digit"}, {"y", "numeric"}}, PatternItem("year", {{"yy", "2-digit"}, {"y", "numeric"}},
&k2DigitNumeric), k2DigitNumeric),
// Sometimes we get L instead of M for month - standalone name. // Sometimes we get L instead of M for month - standalone name.
PatternItem("month", PatternItem("month",
{{"MMMMM", "narrow"}, {{"MMMMM", "narrow"},
@ -82,28 +81,27 @@ static const std::vector<PatternItem>& GetPatternItems() {
{"LLL", "short"}, {"LLL", "short"},
{"LL", "2-digit"}, {"LL", "2-digit"},
{"L", "numeric"}}, {"L", "numeric"}},
&kNarrowLongShort2DigitNumeric), kNarrowLongShort2DigitNumeric),
PatternItem("day", {{"dd", "2-digit"}, {"d", "numeric"}}, PatternItem("day", {{"dd", "2-digit"}, {"d", "numeric"}}, k2DigitNumeric),
&k2DigitNumeric),
PatternItem("hour", PatternItem("hour",
{{"HH", "2-digit"}, {{"HH", "2-digit"},
{"H", "numeric"}, {"H", "numeric"},
{"hh", "2-digit"}, {"hh", "2-digit"},
{"h", "numeric"}}, {"h", "numeric"}},
&k2DigitNumeric), k2DigitNumeric),
PatternItem("minute", {{"mm", "2-digit"}, {"m", "numeric"}}, PatternItem("minute", {{"mm", "2-digit"}, {"m", "numeric"}},
&k2DigitNumeric), k2DigitNumeric),
PatternItem("second", {{"ss", "2-digit"}, {"s", "numeric"}}, PatternItem("second", {{"ss", "2-digit"}, {"s", "numeric"}},
&k2DigitNumeric), k2DigitNumeric),
PatternItem("timeZoneName", {{"zzzz", "long"}, {"z", "short"}}, PatternItem("timeZoneName", {{"zzzz", "long"}, {"z", "short"}},
&kLongShort)}; kLongShort)};
return kPatternItems; return kPatternItems;
} }
class PatternData { class PatternData {
public: public:
PatternData(const std::string property, std::vector<PatternMap> pairs, 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) { : property(std::move(property)), allowed_values(allowed_values) {
for (const auto& pair : pairs) { for (const auto& pair : pairs) {
map.insert(std::make_pair(pair.value, pair.pattern)); map.insert(std::make_pair(pair.value, pair.pattern));
@ -113,7 +111,7 @@ class PatternData {
const std::string property; const std::string property;
std::map<const std::string, const std::string> map; std::map<const std::string, const std::string> map;
std::vector<const char*>* allowed_values; std::vector<const char*> allowed_values;
}; };
enum HourOption { enum HourOption {
@ -122,7 +120,7 @@ enum HourOption {
H_24, H_24,
}; };
static const std::vector<PatternData> CreateCommonData() { const std::vector<PatternData> CreateCommonData() {
std::vector<PatternData> build; std::vector<PatternData> build;
for (const auto& item : GetPatternItems()) { for (const auto& item : GetPatternItems()) {
if (item.property != "hour") { if (item.property != "hour") {
@ -133,20 +131,20 @@ static const std::vector<PatternData> CreateCommonData() {
return build; return build;
} }
static const std::vector<PatternData> CreateData(const char* digit2, const std::vector<PatternData> CreateData(const char* digit2,
const char* numeric) { const char* numeric) {
static std::vector<const char*> k2DigitNumeric = {"2-digit", "numeric"}; const std::vector<const char*> k2DigitNumeric = {"2-digit", "numeric"};
static const std::vector<PatternData> common = CreateCommonData(); const std::vector<PatternData> common = CreateCommonData();
std::vector<PatternData> build(common); std::vector<PatternData> build(common);
build.push_back(PatternData( build.push_back(PatternData(
"hour", {{digit2, "2-digit"}, {numeric, "numeric"}}, &k2DigitNumeric)); "hour", {{digit2, "2-digit"}, {numeric, "numeric"}}, k2DigitNumeric));
return build; return build;
} }
static const std::vector<PatternData>& GetPatternData(HourOption option) { const std::vector<PatternData> GetPatternData(HourOption option) {
static const std::vector<PatternData> data = CreateData("jj", "j"); const std::vector<PatternData> data = CreateData("jj", "j");
static const std::vector<PatternData> data_h12 = CreateData("hh", "h"); const std::vector<PatternData> data_h12 = CreateData("hh", "h");
static const std::vector<PatternData> data_h24 = CreateData("HH", "H"); const std::vector<PatternData> data_h24 = CreateData("HH", "H");
switch (option) { switch (option) {
case HourOption::H_12: case HourOption::H_12:
return data_h12; return data_h12;
@ -160,7 +158,7 @@ static const std::vector<PatternData>& GetPatternData(HourOption option) {
void SetPropertyFromPattern(Isolate* isolate, const std::string& pattern, void SetPropertyFromPattern(Isolate* isolate, const std::string& pattern,
Handle<JSObject> options) { Handle<JSObject> options) {
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
const std::vector<PatternItem>& items = GetPatternItems(); const std::vector<PatternItem> items = GetPatternItems();
for (const auto& item : items) { for (const auto& item : items) {
for (const auto& pair : item.pairs) { for (const auto& pair : item.pairs) {
if (pattern.find(pair.pattern) != std::string::npos) { if (pattern.find(pair.pattern) != std::string::npos) {
@ -410,7 +408,7 @@ Maybe<std::string> JSDateTimeFormat::OptionsToSkeleton(
for (const auto& item : GetPatternData(hour_option)) { for (const auto& item : GetPatternData(hour_option)) {
std::unique_ptr<char[]> input; std::unique_ptr<char[]> input;
Maybe<bool> maybe_get_option = Intl::GetStringOption( 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); "Intl.DateTimeFormat", &input);
MAYBE_RETURN(maybe_get_option, Nothing<std::string>()); MAYBE_RETURN(maybe_get_option, Nothing<std::string>());
if (maybe_get_option.FromJust()) { if (maybe_get_option.FromJust()) {
@ -799,7 +797,7 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::Initialize(
MAYBE_RETURN(maybe_found_matcher, Handle<JSDateTimeFormat>()); MAYBE_RETURN(maybe_found_matcher, Handle<JSDateTimeFormat>());
// 17. Let timeZone be ? Get(options, "timeZone"). // 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; std::unique_ptr<char[]> timezone = nullptr;
Maybe<bool> maybe_timezone = Intl::GetStringOption( Maybe<bool> maybe_timezone = Intl::GetStringOption(
isolate, options, "timeZone", empty_values, kService, &timezone); isolate, options, "timeZone", empty_values, kService, &timezone);

View File

@ -49,12 +49,12 @@ Maybe<bool> InsertOptionsIntoLocale(Isolate* isolate,
CHECK(isolate); CHECK(isolate);
CHECK(icu_locale); CHECK(icu_locale);
static std::vector<const char*> hour_cycle_values = {"h11", "h12", "h23", const std::vector<const char*> hour_cycle_values = {"h11", "h12", "h23",
"h24"}; "h24"};
static std::vector<const char*> case_first_values = {"upper", "lower", const std::vector<const char*> case_first_values = {"upper", "lower",
"false"}; "false"};
static std::vector<const char*> empty_values = {}; const std::vector<const char*> empty_values = {};
static const std::array<OptionData, 6> kOptionToUnicodeTagMap = { const std::array<OptionData, 6> kOptionToUnicodeTagMap = {
{{"calendar", "ca", &empty_values, false}, {{"calendar", "ca", &empty_values, false},
{"collation", "co", &empty_values, false}, {"collation", "co", &empty_values, false},
{"hourCycle", "hc", &hour_cycle_values, false}, {"hourCycle", "hc", &hour_cycle_values, false},

View File

@ -272,7 +272,7 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::Initialize(
// "percent", "currency" », "decimal"). // "percent", "currency" », "decimal").
const char* service = "Intl.NumberFormat"; const char* service = "Intl.NumberFormat";
std::unique_ptr<char[]> style_cstr; std::unique_ptr<char[]> style_cstr;
static std::vector<const char*> style_values = {"decimal", "percent", const std::vector<const char*> style_values = {"decimal", "percent",
"currency"}; "currency"};
Maybe<bool> found_style = Intl::GetStringOption( Maybe<bool> found_style = Intl::GetStringOption(
isolate, options, "style", style_values, service, &style_cstr); isolate, options, "style", style_values, service, &style_cstr);
@ -293,7 +293,7 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::Initialize(
// 14. Let currency be ? GetOption(options, "currency", "string", undefined, // 14. Let currency be ? GetOption(options, "currency", "string", undefined,
// undefined). // undefined).
std::unique_ptr<char[]> currency_cstr; 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( Maybe<bool> found_currency = Intl::GetStringOption(
isolate, options, "currency", empty_values, service, &currency_cstr); isolate, options, "currency", empty_values, service, &currency_cstr);
MAYBE_RETURN(found_currency, MaybeHandle<JSNumberFormat>()); MAYBE_RETURN(found_currency, MaybeHandle<JSNumberFormat>());
@ -335,7 +335,7 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::Initialize(
// 18. Let currencyDisplay be ? GetOption(options, "currencyDisplay", // 18. Let currencyDisplay be ? GetOption(options, "currencyDisplay",
// "string", « "code", "symbol", "name" », "symbol"). // "string", « "code", "symbol", "name" », "symbol").
std::unique_ptr<char[]> currency_display_cstr; std::unique_ptr<char[]> currency_display_cstr;
static std::vector<const char*> currency_display_values = {"code", "name", const std::vector<const char*> currency_display_values = {"code", "name",
"symbol"}; "symbol"};
Maybe<bool> found_currency_display = Intl::GetStringOption( Maybe<bool> found_currency_display = Intl::GetStringOption(
isolate, options, "currencyDisplay", currency_display_values, service, isolate, options, "currencyDisplay", currency_display_values, service,