Skip to content

Commit

Permalink
[intl] Update Intl Locale Info
Browse files Browse the repository at this point in the history
Add two flags and two counters
One flag to stage/ship the Intl Locale API after
tc39/proposal-intl-locale-info#67
One flag to remove the getters obsoleted by the PR67

Add two counters to measure the usage of these two

Bug: v8:13834, v8:13835
Change-Id: Ic29ffe9b6114d6f5d46224817e7f38bb6147b9e2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4355215
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Reviewed-by: Jakob Linke <jgruber@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: Adam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#86988}
  • Loading branch information
FrankYFTang authored and V8 LUCI CQ committed Apr 6, 2023
1 parent f6bdedb commit 1950f83
Show file tree
Hide file tree
Showing 17 changed files with 222 additions and 99 deletions.
2 changes: 2 additions & 0 deletions include/v8-isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ class V8_EXPORT Isolate {
kInvalidatedNumberStringPrototypeNoReplaceProtector = 118,
kRegExpUnicodeSetIncompatibilitiesWithUnicodeMode = 119, // Unused.
kImportAssertionDeprecatedSyntax = 120,
kLocaleInfoObsoletedGetters = 121,
kLocaleInfoFunctions = 122,

// If you add new values here, you'll also need to update Chromium's:
// web_feature.mojom, use_counter_callback.cc, and enums.xml. V8 changes to
Expand Down
14 changes: 14 additions & 0 deletions src/builtins/builtins-definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,20 @@ namespace internal {
CPP(LocalePrototypeCollation) \
/* ecma402 #sec-Intl.Locale.prototype.collations */ \
CPP(LocalePrototypeCollations) \
/* ecma402 #sec-Intl.Locale.prototype.getCalendars */ \
CPP(LocalePrototypeGetCalendars) \
/* ecma402 #sec-Intl.Locale.prototype.getCollations */ \
CPP(LocalePrototypeGetCollations) \
/* ecma402 #sec-Intl.Locale.prototype.getHourCycles */ \
CPP(LocalePrototypeGetHourCycles) \
/* ecma402 #sec-Intl.Locale.prototype.getNumberingSystems */ \
CPP(LocalePrototypeGetNumberingSystems) \
/* ecma402 #sec-Intl.Locale.prototype.getTimeZones */ \
CPP(LocalePrototypeGetTimeZones) \
/* ecma402 #sec-Intl.Locale.prototype.getTextInfo */ \
CPP(LocalePrototypeGetTextInfo) \
/* ecma402 #sec-Intl.Locale.prototype.getWeekInfo */ \
CPP(LocalePrototypeGetWeekInfo) \
/* ecma402 #sec-Intl.Locale.prototype.hourCycle */ \
CPP(LocalePrototypeHourCycle) \
/* ecma402 #sec-Intl.Locale.prototype.hourCycles */ \
Expand Down
78 changes: 71 additions & 7 deletions src/builtins/builtins-intl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -721,47 +721,111 @@ BUILTIN(LocalePrototypeMinimize) {
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::Minimize(isolate, locale));
}

BUILTIN(LocalePrototypeGetCalendars) {
HandleScope scope(isolate);
isolate->CountUsage(v8::Isolate::UseCounterFeature::kLocaleInfoFunctions);
CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.getCalendars");
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::GetCalendars(isolate, locale));
}

BUILTIN(LocalePrototypeGetCollations) {
HandleScope scope(isolate);
isolate->CountUsage(v8::Isolate::UseCounterFeature::kLocaleInfoFunctions);
CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.getCollations");
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::GetCollations(isolate, locale));
}

BUILTIN(LocalePrototypeGetHourCycles) {
HandleScope scope(isolate);
isolate->CountUsage(v8::Isolate::UseCounterFeature::kLocaleInfoFunctions);
CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.getHourCycles");
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::GetHourCycles(isolate, locale));
}

BUILTIN(LocalePrototypeGetNumberingSystems) {
HandleScope scope(isolate);
isolate->CountUsage(v8::Isolate::UseCounterFeature::kLocaleInfoFunctions);
CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.getNumberingSystems");
RETURN_RESULT_OR_FAILURE(isolate,
JSLocale::GetNumberingSystems(isolate, locale));
}

BUILTIN(LocalePrototypeGetTextInfo) {
HandleScope scope(isolate);
isolate->CountUsage(v8::Isolate::UseCounterFeature::kLocaleInfoFunctions);
CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.getTextInfo");
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::GetTextInfo(isolate, locale));
}

BUILTIN(LocalePrototypeGetTimeZones) {
HandleScope scope(isolate);
isolate->CountUsage(v8::Isolate::UseCounterFeature::kLocaleInfoFunctions);
CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.getTimeZones");
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::GetTimeZones(isolate, locale));
}

BUILTIN(LocalePrototypeGetWeekInfo) {
HandleScope scope(isolate);
isolate->CountUsage(v8::Isolate::UseCounterFeature::kLocaleInfoFunctions);
CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.getWeekInfo");
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::GetWeekInfo(isolate, locale));
}

BUILTIN(LocalePrototypeCalendars) {
HandleScope scope(isolate);
isolate->CountUsage(
v8::Isolate::UseCounterFeature::kLocaleInfoObsoletedGetters);
CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.calendars");
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::Calendars(isolate, locale));
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::GetCalendars(isolate, locale));
}

BUILTIN(LocalePrototypeCollations) {
HandleScope scope(isolate);
isolate->CountUsage(
v8::Isolate::UseCounterFeature::kLocaleInfoObsoletedGetters);
CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.collations");
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::Collations(isolate, locale));
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::GetCollations(isolate, locale));
}

BUILTIN(LocalePrototypeHourCycles) {
HandleScope scope(isolate);
isolate->CountUsage(
v8::Isolate::UseCounterFeature::kLocaleInfoObsoletedGetters);
CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.hourCycles");
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::HourCycles(isolate, locale));
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::GetHourCycles(isolate, locale));
}

BUILTIN(LocalePrototypeNumberingSystems) {
HandleScope scope(isolate);
isolate->CountUsage(
v8::Isolate::UseCounterFeature::kLocaleInfoObsoletedGetters);
CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.numberingSystems");
RETURN_RESULT_OR_FAILURE(isolate,
JSLocale::NumberingSystems(isolate, locale));
JSLocale::GetNumberingSystems(isolate, locale));
}

BUILTIN(LocalePrototypeTextInfo) {
HandleScope scope(isolate);
isolate->CountUsage(
v8::Isolate::UseCounterFeature::kLocaleInfoObsoletedGetters);
CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.textInfo");
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::TextInfo(isolate, locale));
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::GetTextInfo(isolate, locale));
}

BUILTIN(LocalePrototypeTimeZones) {
HandleScope scope(isolate);
isolate->CountUsage(
v8::Isolate::UseCounterFeature::kLocaleInfoObsoletedGetters);
CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.timeZones");
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::TimeZones(isolate, locale));
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::GetTimeZones(isolate, locale));
}

BUILTIN(LocalePrototypeWeekInfo) {
HandleScope scope(isolate);
isolate->CountUsage(
v8::Isolate::UseCounterFeature::kLocaleInfoObsoletedGetters);
CHECK_RECEIVER(JSLocale, locale, "Intl.Locale.prototype.weekInfo");
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::WeekInfo(isolate, locale));
RETURN_RESULT_OR_FAILURE(isolate, JSLocale::GetWeekInfo(isolate, locale));
}

BUILTIN(RelativeTimeFormatSupportedLocalesOf) {
Expand Down
7 changes: 7 additions & 0 deletions src/debug/debug-evaluate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,13 @@ DebugInfo::SideEffectState BuiltinGetSideEffectState(Builtin id) {
case Builtin::kLocalePrototypeCaseFirst:
case Builtin::kLocalePrototypeCollation:
case Builtin::kLocalePrototypeCollations:
case Builtin::kLocalePrototypeGetCalendars:
case Builtin::kLocalePrototypeGetCollations:
case Builtin::kLocalePrototypeGetHourCycles:
case Builtin::kLocalePrototypeGetNumberingSystems:
case Builtin::kLocalePrototypeGetTextInfo:
case Builtin::kLocalePrototypeGetTimeZones:
case Builtin::kLocalePrototypeGetWeekInfo:
case Builtin::kLocalePrototypeHourCycle:
case Builtin::kLocalePrototypeHourCycles:
case Builtin::kLocalePrototypeLanguage:
Expand Down
11 changes: 8 additions & 3 deletions src/flags/flag-definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,14 @@ DEFINE_BOOL(harmony_shipping, true, "enable all shipped harmony features")
V(harmony_iterator_helpers, "JavaScript iterator helpers")

#ifdef V8_INTL_SUPPORT
#define HARMONY_INPROGRESS(V) \
HARMONY_INPROGRESS_BASE(V) \
V(harmony_intl_best_fit_matcher, "Intl BestFitMatcher") \
#define HARMONY_INPROGRESS(V) \
HARMONY_INPROGRESS_BASE(V) \
V(harmony_intl_best_fit_matcher, "Intl BestFitMatcher") \
/* Following two flags should ship the same time but may stage */ \
/* differently . */ \
V(harmony_remove_intl_locale_info_getters, \
"Remove Obsoleted Intl Locale Info getters") \
V(harmony_intl_locale_info_func, "Intl Locale Info API as functions") \
V(harmony_intl_duration_format, "Intl DurationFormat API")
#else
#define HARMONY_INPROGRESS(V) HARMONY_INPROGRESS_BASE(V)
Expand Down
56 changes: 40 additions & 16 deletions src/init/bootstrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3155,22 +3155,24 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
factory->numberingSystem_string(),
Builtin::kLocalePrototypeNumberingSystem, true);

// Intl Locale Info functions
SimpleInstallGetter(isolate(), prototype, factory->calendars_string(),
Builtin::kLocalePrototypeCalendars, true);
SimpleInstallGetter(isolate(), prototype, factory->collations_string(),
Builtin::kLocalePrototypeCollations, true);
SimpleInstallGetter(isolate(), prototype, factory->hourCycles_string(),
Builtin::kLocalePrototypeHourCycles, true);
SimpleInstallGetter(isolate(), prototype,
factory->numberingSystems_string(),
Builtin::kLocalePrototypeNumberingSystems, true);
SimpleInstallGetter(isolate(), prototype, factory->textInfo_string(),
Builtin::kLocalePrototypeTextInfo, true);
SimpleInstallGetter(isolate(), prototype, factory->timeZones_string(),
Builtin::kLocalePrototypeTimeZones, true);
SimpleInstallGetter(isolate(), prototype, factory->weekInfo_string(),
Builtin::kLocalePrototypeWeekInfo, true);
if (!v8_flags.harmony_remove_intl_locale_info_getters) {
// Intl Locale Info functions
SimpleInstallGetter(isolate(), prototype, factory->calendars_string(),
Builtin::kLocalePrototypeCalendars, true);
SimpleInstallGetter(isolate(), prototype, factory->collations_string(),
Builtin::kLocalePrototypeCollations, true);
SimpleInstallGetter(isolate(), prototype, factory->hourCycles_string(),
Builtin::kLocalePrototypeHourCycles, true);
SimpleInstallGetter(isolate(), prototype,
factory->numberingSystems_string(),
Builtin::kLocalePrototypeNumberingSystems, true);
SimpleInstallGetter(isolate(), prototype, factory->textInfo_string(),
Builtin::kLocalePrototypeTextInfo, true);
SimpleInstallGetter(isolate(), prototype, factory->timeZones_string(),
Builtin::kLocalePrototypeTimeZones, true);
SimpleInstallGetter(isolate(), prototype, factory->weekInfo_string(),
Builtin::kLocalePrototypeWeekInfo, true);
}
}

{ // -- D i s p l a y N a m e s
Expand Down Expand Up @@ -4533,6 +4535,7 @@ EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_rab_gsab_transfer)

#ifdef V8_INTL_SUPPORT
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_intl_best_fit_matcher)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_remove_intl_locale_info_getters)
#endif // V8_INTL_SUPPORT

#undef EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE
Expand Down Expand Up @@ -5671,6 +5674,27 @@ void Genesis::InitializeGlobal_harmony_intl_number_format_v3() {
#endif // V8_INTL_SUPPORT

#ifdef V8_INTL_SUPPORT
void Genesis::InitializeGlobal_harmony_intl_locale_info_func() {
if (!v8_flags.harmony_intl_locale_info_func) return;
Handle<JSObject> prototype(
JSObject::cast(native_context()->intl_locale_function().prototype()),
isolate_);
SimpleInstallFunction(isolate(), prototype, "getCalendars",
Builtin::kLocalePrototypeGetCalendars, 0, false);
SimpleInstallFunction(isolate(), prototype, "getCollations",
Builtin::kLocalePrototypeGetCollations, 0, false);
SimpleInstallFunction(isolate(), prototype, "getHourCycles",
Builtin::kLocalePrototypeGetHourCycles, 0, false);
SimpleInstallFunction(isolate(), prototype, "getNumberingSystems",
Builtin::kLocalePrototypeGetNumberingSystems, 0, false);
SimpleInstallFunction(isolate(), prototype, "getTimeZones",
Builtin::kLocalePrototypeGetTimeZones, 0, false);
SimpleInstallFunction(isolate(), prototype, "getTextInfo",
Builtin::kLocalePrototypeGetTextInfo, 0, false);
SimpleInstallFunction(isolate(), prototype, "getWeekInfo",
Builtin::kLocalePrototypeGetWeekInfo, 0, false);
}

void Genesis::InitializeGlobal_harmony_intl_duration_format() {
if (!v8_flags.harmony_intl_duration_format) return;
Handle<JSObject> intl = Handle<JSObject>::cast(
Expand Down
28 changes: 14 additions & 14 deletions src/objects/js-locale.cc
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,8 @@ MaybeHandle<JSArray> CalendarsForLocale(Isolate* isolate,

} // namespace

MaybeHandle<JSArray> JSLocale::Calendars(Isolate* isolate,
Handle<JSLocale> locale) {
MaybeHandle<JSArray> JSLocale::GetCalendars(Isolate* isolate,
Handle<JSLocale> locale) {
icu::Locale icu_locale(*(locale->icu_locale().raw()));
return CalendarsForLocale(isolate, icu_locale, true, false);
}
Expand All @@ -526,16 +526,16 @@ MaybeHandle<JSArray> Intl::AvailableCalendars(Isolate* isolate) {
return CalendarsForLocale(isolate, icu_locale, false, true);
}

MaybeHandle<JSArray> JSLocale::Collations(Isolate* isolate,
Handle<JSLocale> locale) {
MaybeHandle<JSArray> JSLocale::GetCollations(Isolate* isolate,
Handle<JSLocale> locale) {
icu::Locale icu_locale(*(locale->icu_locale().raw()));
return GetKeywordValuesFromLocale<icu::Collator>(
isolate, "collations", "co", icu_locale, Intl::RemoveCollation, true,
true);
}

MaybeHandle<JSArray> JSLocale::HourCycles(Isolate* isolate,
Handle<JSLocale> locale) {
MaybeHandle<JSArray> JSLocale::GetHourCycles(Isolate* isolate,
Handle<JSLocale> locale) {
// Let preferred be loc.[[HourCycle]].
// Let locale be loc.[[Locale]].
icu::Locale icu_locale(*(locale->icu_locale().raw()));
Expand Down Expand Up @@ -593,8 +593,8 @@ MaybeHandle<JSArray> JSLocale::HourCycles(Isolate* isolate,
return factory->NewJSArrayWithElements(fixed_array);
}

MaybeHandle<JSArray> JSLocale::NumberingSystems(Isolate* isolate,
Handle<JSLocale> locale) {
MaybeHandle<JSArray> JSLocale::GetNumberingSystems(Isolate* isolate,
Handle<JSLocale> locale) {
// Let preferred be loc.[[NumberingSystem]].

// Let locale be loc.[[Locale]].
Expand Down Expand Up @@ -623,8 +623,8 @@ MaybeHandle<JSArray> JSLocale::NumberingSystems(Isolate* isolate,
return factory->NewJSArrayWithElements(fixed_array);
}

MaybeHandle<Object> JSLocale::TimeZones(Isolate* isolate,
Handle<JSLocale> locale) {
MaybeHandle<Object> JSLocale::GetTimeZones(Isolate* isolate,
Handle<JSLocale> locale) {
// Let loc be the this value.

// Perform ? RequireInternalSlot(loc, [[InitializedLocale]])
Expand Down Expand Up @@ -663,8 +663,8 @@ MaybeHandle<Object> JSLocale::TimeZones(Isolate* isolate,
return Intl::ToJSArray(isolate, nullptr, enumeration.get(), nullptr, true);
}

MaybeHandle<JSObject> JSLocale::TextInfo(Isolate* isolate,
Handle<JSLocale> locale) {
MaybeHandle<JSObject> JSLocale::GetTextInfo(Isolate* isolate,
Handle<JSLocale> locale) {
// Let loc be the this value.

// Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
Expand Down Expand Up @@ -703,8 +703,8 @@ MaybeHandle<JSObject> JSLocale::TextInfo(Isolate* isolate,
return info;
}

MaybeHandle<JSObject> JSLocale::WeekInfo(Isolate* isolate,
Handle<JSLocale> locale) {
MaybeHandle<JSObject> JSLocale::GetWeekInfo(Isolate* isolate,
Handle<JSLocale> locale) {
// Let loc be the this value.

// Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
Expand Down
14 changes: 7 additions & 7 deletions src/objects/js-locale.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ class JSLocale : public TorqueGeneratedJSLocale<JSLocale, JSObject> {
static MaybeHandle<JSLocale> Minimize(Isolate* isolate,
Handle<JSLocale> locale);

V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> Calendars(
V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> GetCalendars(
Isolate* isolate, Handle<JSLocale> locale);
V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> Collations(
V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> GetCollations(
Isolate* isolate, Handle<JSLocale> locale);
V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> HourCycles(
V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> GetHourCycles(
Isolate* isolate, Handle<JSLocale> locale);
V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> NumberingSystems(
V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> GetNumberingSystems(
Isolate* isolate, Handle<JSLocale> locale);
V8_WARN_UNUSED_RESULT static MaybeHandle<JSObject> TextInfo(
V8_WARN_UNUSED_RESULT static MaybeHandle<JSObject> GetTextInfo(
Isolate* isolate, Handle<JSLocale> locale);
V8_WARN_UNUSED_RESULT static MaybeHandle<Object> TimeZones(
V8_WARN_UNUSED_RESULT static MaybeHandle<Object> GetTimeZones(
Isolate* isolate, Handle<JSLocale> locale);
V8_WARN_UNUSED_RESULT static MaybeHandle<JSObject> WeekInfo(
V8_WARN_UNUSED_RESULT static MaybeHandle<JSObject> GetWeekInfo(
Isolate* isolate, Handle<JSLocale> locale);

static Handle<Object> Language(Isolate* isolate, Handle<JSLocale> locale);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-intl-locale-info-func

// Test the return items of calendars fit 'type'
// Test the return items of getCalendars() fit 'type'
let a_to_z = "abcdefghijklmnopqrstuvwxyz";
let regex = /^[a-zA-Z0-9]{3,8}(-[a-zA-Z0-9]{3,8})*$/;
for (var i = 0; i < a_to_z.length; i++) {
for (var j = 0; j < a_to_z.length; j++) {
let l = a_to_z[i] + a_to_z[j];
let locale = new Intl.Locale(l);
locale.calendars.forEach(function(tokens) {
locale.getCalendars().forEach(function(tokens) {
assertTrue(regex.test(tokens),
locale + ".calendars [" + locale.calendars +
locale + ".getCalendars [" + locale.getCalendars() +
"] but '" + tokens + "' does not meet 'type: alphanum{3,8}(sep alphanum{3,8})*'");
});
}
Expand Down
Loading

0 comments on commit 1950f83

Please sign in to comment.