Skip to content

Commit

Permalink
[JSC] Reflect the latest update in Intl.Locale info proposal
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=252444
rdar://105570888

Reviewed by Mark Lam.

January TC39 meeting decided that Intl.Locale info getters should be replaced with getXXX methods[1].
This patch reflects this spec change to our implementation.

[1]: tc39/proposal-intl-locale-info@c6daaee

* JSTests/stress/intl-date-pattern-includes-literal-text.js:
* JSTests/stress/intl-locale-info.js:
(throw.new.Error):
(shouldBe):
(let.l.new.Intl.Locale.shouldBe):
* JSTests/stress/intl-locale-invalid-hourCycles.js:
(main):
* JSTests/test262/config.yaml:
* Source/JavaScriptCore/runtime/IntlLocalePrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):

Canonical link: https://commits.webkit.org/260412@main
  • Loading branch information
Constellation committed Feb 17, 2023
1 parent a36079d commit 7e2deb2
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 119 deletions.
6 changes: 3 additions & 3 deletions JSTests/stress/intl-date-pattern-includes-literal-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ shouldBe(new Intl.DateTimeFormat("fr", {hour: "numeric", hour12: false}).format(
shouldBe(new Intl.DateTimeFormat("fr", {hour: "numeric", hourCycle: 'h24'}).format(new Date(2021, 2, 3, 23)), '23 h');
shouldBe(new Intl.DateTimeFormat("fr", {hour: "numeric", hourCycle: 'h23'}).format(new Date(2021, 2, 3, 23)), '23 h');

shouldBe(JSON.stringify(new Intl.Locale("fr", {hourCycle: 'h24'}).hourCycles), `["h24"]`);
shouldBe(JSON.stringify(new Intl.Locale("fr", {hourCycle: 'h23'}).hourCycles), `["h23"]`);
shouldBe(JSON.stringify(new Intl.Locale("fr").hourCycles), `["h23"]`);
shouldBe(JSON.stringify(new Intl.Locale("fr", {hourCycle: 'h24'}).getHourCycles()), `["h24"]`);
shouldBe(JSON.stringify(new Intl.Locale("fr", {hourCycle: 'h23'}).getHourCycles()), `["h23"]`);
shouldBe(JSON.stringify(new Intl.Locale("fr").getHourCycles()), `["h23"]`);
120 changes: 60 additions & 60 deletions JSTests/stress/intl-locale-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,117 +10,117 @@ function shouldBeOneOf(actual, expectedArray) {

{
let he = new Intl.Locale("he")
shouldBe(JSON.stringify(he.weekInfo), `{"firstDay":7,"weekend":[5,6],"minimalDays":1}`);
shouldBe(JSON.stringify(he.getWeekInfo()), `{"firstDay":7,"weekend":[5,6],"minimalDays":1}`);
let af = new Intl.Locale("af")
shouldBe(JSON.stringify(af.weekInfo), `{"firstDay":7,"weekend":[6,7],"minimalDays":1}`);
shouldBe(JSON.stringify(af.getWeekInfo()), `{"firstDay":7,"weekend":[6,7],"minimalDays":1}`);
let enGB = new Intl.Locale("en-GB")
shouldBe(JSON.stringify(enGB.weekInfo), `{"firstDay":1,"weekend":[6,7],"minimalDays":4}`);
shouldBe(JSON.stringify(enGB.getWeekInfo()), `{"firstDay":1,"weekend":[6,7],"minimalDays":4}`);
let msBN = new Intl.Locale("ms-BN");
// "weekend" should be [5,7]. But currently ICU/CLDR does not support representing non-contiguous weekend.
shouldBe(JSON.stringify(msBN.weekInfo), `{"firstDay":1,"weekend":[6,7],"minimalDays":1}`);
shouldBe(JSON.stringify(msBN.getWeekInfo()), `{"firstDay":1,"weekend":[6,7],"minimalDays":1}`);
}
{
let l = new Intl.Locale("ar")
shouldBe(JSON.stringify(l.textInfo), `{"direction":"rtl"}`);
shouldBe(JSON.stringify(l.getTextInfo()), `{"direction":"rtl"}`);
}
{
let locale = new Intl.Locale("ar")
shouldBe(JSON.stringify(locale.calendars), `["gregory","coptic","islamic","islamic-civil","islamic-tbla"]`);
shouldBe(JSON.stringify(locale.collations), `["compat","emoji","eor"]`);
shouldBe(JSON.stringify(locale.getCalendars()), `["gregory","coptic","islamic","islamic-civil","islamic-tbla"]`);
shouldBe(JSON.stringify(locale.getCollations()), `["compat","emoji","eor"]`);
shouldBe(locale.hourCycle, undefined);
shouldBe(JSON.stringify(locale.hourCycles), `["h12"]`);
let ns = JSON.stringify(locale.numberingSystems);
shouldBe(JSON.stringify(locale.getHourCycles()), `["h12"]`);
let ns = JSON.stringify(locale.getNumberingSystems());
shouldBe(ns === `["arab"]` || ns === `["latn"]`, true);
shouldBe(locale.timeZones, undefined);
shouldBe(locale.getTimeZones(), undefined);
}
{
let locale = new Intl.Locale("ar-EG")
shouldBe(JSON.stringify(locale.calendars), `["gregory","coptic","islamic","islamic-civil","islamic-tbla"]`);
shouldBe(JSON.stringify(locale.collations), `["compat","emoji","eor"]`);
shouldBe(JSON.stringify(locale.getCalendars()), `["gregory","coptic","islamic","islamic-civil","islamic-tbla"]`);
shouldBe(JSON.stringify(locale.getCollations()), `["compat","emoji","eor"]`);
shouldBe(locale.hourCycle, undefined);
shouldBe(JSON.stringify(locale.hourCycles), `["h12"]`);
shouldBe(JSON.stringify(locale.numberingSystems), `["arab"]`);
shouldBe(JSON.stringify(locale.timeZones), `["Africa/Cairo"]`);
shouldBe(JSON.stringify(locale.getHourCycles()), `["h12"]`);
shouldBe(JSON.stringify(locale.getNumberingSystems()), `["arab"]`);
shouldBe(JSON.stringify(locale.getTimeZones()), `["Africa/Cairo"]`);
}
{
let locale = new Intl.Locale("ar-SA")
let calendars = JSON.stringify(locale.calendars);
let calendars = JSON.stringify(locale.getCalendars());
shouldBe(calendars === `["islamic-umalqura","islamic-rgsa","islamic","gregory"]` || calendars === `["islamic-umalqura","gregory","islamic","islamic-rgsa"]`, true);
shouldBe(JSON.stringify(locale.collations), `["compat","emoji","eor"]`);
shouldBe(JSON.stringify(locale.getCollations()), `["compat","emoji","eor"]`);
shouldBe(locale.hourCycle, undefined);
shouldBe(JSON.stringify(locale.hourCycles), `["h12"]`);
shouldBe(JSON.stringify(locale.numberingSystems), `["arab"]`);
shouldBe(JSON.stringify(locale.timeZones), `["Asia/Riyadh"]`);
shouldBe(JSON.stringify(locale.getHourCycles()), `["h12"]`);
shouldBe(JSON.stringify(locale.getNumberingSystems()), `["arab"]`);
shouldBe(JSON.stringify(locale.getTimeZones()), `["Asia/Riyadh"]`);
}
{
let locale = new Intl.Locale("ja")
shouldBe(JSON.stringify(locale.calendars), `["gregory","japanese"]`);
shouldBe(JSON.stringify(locale.collations), `["unihan","emoji","eor"]`);
shouldBe(JSON.stringify(locale.getCalendars()), `["gregory","japanese"]`);
shouldBe(JSON.stringify(locale.getCollations()), `["unihan","emoji","eor"]`);
shouldBe(locale.hourCycle, undefined);
shouldBe(JSON.stringify(locale.hourCycles), `["h23"]`);
shouldBe(JSON.stringify(locale.numberingSystems), `["latn"]`);
shouldBe(locale.timeZones, undefined);
shouldBe(JSON.stringify(locale.getHourCycles()), `["h23"]`);
shouldBe(JSON.stringify(locale.getNumberingSystems()), `["latn"]`);
shouldBe(locale.getTimeZones(), undefined);
}
{
let locale = new Intl.Locale("ja-JP")
shouldBe(JSON.stringify(locale.calendars), `["gregory","japanese"]`);
shouldBe(JSON.stringify(locale.collations), `["unihan","emoji","eor"]`);
shouldBe(JSON.stringify(locale.getCalendars()), `["gregory","japanese"]`);
shouldBe(JSON.stringify(locale.getCollations()), `["unihan","emoji","eor"]`);
shouldBe(locale.hourCycle, undefined);
shouldBe(JSON.stringify(locale.hourCycles), `["h23"]`);
shouldBe(JSON.stringify(locale.numberingSystems), `["latn"]`);
shouldBe(JSON.stringify(locale.timeZones), `["Asia/Tokyo"]`);
shouldBe(JSON.stringify(locale.getHourCycles()), `["h23"]`);
shouldBe(JSON.stringify(locale.getNumberingSystems()), `["latn"]`);
shouldBe(JSON.stringify(locale.getTimeZones()), `["Asia/Tokyo"]`);
}
{
let locale = new Intl.Locale("en-US")
shouldBe(JSON.stringify(locale.calendars), `["gregory"]`);
shouldBe(JSON.stringify(locale.collations), `["emoji","eor"]`);
shouldBe(JSON.stringify(locale.getCalendars()), `["gregory"]`);
shouldBe(JSON.stringify(locale.getCollations()), `["emoji","eor"]`);
shouldBe(locale.hourCycle, undefined);
shouldBe(JSON.stringify(locale.hourCycles), `["h12"]`);
shouldBe(JSON.stringify(locale.numberingSystems), `["latn"]`);
shouldBe(JSON.stringify(locale.timeZones), `["America/Adak","America/Anchorage","America/Boise","America/Chicago","America/Denver","America/Detroit","America/Indiana/Knox","America/Indiana/Marengo","America/Indiana/Petersburg","America/Indiana/Tell_City","America/Indiana/Vevay","America/Indiana/Vincennes","America/Indiana/Winamac","America/Indianapolis","America/Juneau","America/Kentucky/Monticello","America/Los_Angeles","America/Louisville","America/Menominee","America/Metlakatla","America/New_York","America/Nome","America/North_Dakota/Beulah","America/North_Dakota/Center","America/North_Dakota/New_Salem","America/Phoenix","America/Sitka","America/Yakutat","Pacific/Honolulu"]`);
shouldBe(JSON.stringify(locale.getHourCycles()), `["h12"]`);
shouldBe(JSON.stringify(locale.getNumberingSystems()), `["latn"]`);
shouldBe(JSON.stringify(locale.getTimeZones()), `["America/Adak","America/Anchorage","America/Boise","America/Chicago","America/Denver","America/Detroit","America/Indiana/Knox","America/Indiana/Marengo","America/Indiana/Petersburg","America/Indiana/Tell_City","America/Indiana/Vevay","America/Indiana/Vincennes","America/Indiana/Winamac","America/Indianapolis","America/Juneau","America/Kentucky/Monticello","America/Los_Angeles","America/Louisville","America/Menominee","America/Metlakatla","America/New_York","America/Nome","America/North_Dakota/Beulah","America/North_Dakota/Center","America/North_Dakota/New_Salem","America/Phoenix","America/Sitka","America/Yakutat","Pacific/Honolulu"]`);
}
{
let locale = new Intl.Locale("en-NZ")
shouldBe(JSON.stringify(locale.calendars), `["gregory"]`);
shouldBe(JSON.stringify(locale.collations), `["emoji","eor"]`);
shouldBe(JSON.stringify(locale.getCalendars()), `["gregory"]`);
shouldBe(JSON.stringify(locale.getCollations()), `["emoji","eor"]`);
shouldBe(locale.hourCycle, undefined);
shouldBe(JSON.stringify(locale.hourCycles), `["h12"]`);
shouldBe(JSON.stringify(locale.numberingSystems), `["latn"]`);
shouldBe(JSON.stringify(locale.timeZones), `["Pacific/Auckland","Pacific/Chatham"]`);
shouldBe(JSON.stringify(locale.getHourCycles()), `["h12"]`);
shouldBe(JSON.stringify(locale.getNumberingSystems()), `["latn"]`);
shouldBe(JSON.stringify(locale.getTimeZones()), `["Pacific/Auckland","Pacific/Chatham"]`);
}
{
let locale = new Intl.Locale("zh")
shouldBe(JSON.stringify(locale.calendars), `["gregory","chinese"]`);
shouldBe(JSON.stringify(locale.collations), `["pinyin","big5han","gb2312","stroke","unihan","zhuyin","emoji","eor"]`);
shouldBe(JSON.stringify(locale.getCalendars()), `["gregory","chinese"]`);
shouldBe(JSON.stringify(locale.getCollations()), `["pinyin","big5han","gb2312","stroke","unihan","zhuyin","emoji","eor"]`);
shouldBe(locale.hourCycle, undefined);
shouldBeOneOf(JSON.stringify(locale.hourCycles), [ `["h23"]`, `["h12"]` ]);
shouldBe(JSON.stringify(locale.numberingSystems), `["latn"]`);
shouldBe(locale.timeZones, undefined);
shouldBeOneOf(JSON.stringify(locale.getHourCycles()), [ `["h23"]`, `["h12"]` ]);
shouldBe(JSON.stringify(locale.getNumberingSystems()), `["latn"]`);
shouldBe(locale.getTimeZones(), undefined);
}
{
let locale = new Intl.Locale("zh-TW")
shouldBe(JSON.stringify(locale.calendars), `["gregory","roc","chinese"]`);
shouldBe(JSON.stringify(locale.collations), `["stroke","big5han","gb2312","pinyin","unihan","zhuyin","emoji","eor"]`);
shouldBe(JSON.stringify(locale.getCalendars()), `["gregory","roc","chinese"]`);
shouldBe(JSON.stringify(locale.getCollations()), `["stroke","big5han","gb2312","pinyin","unihan","zhuyin","emoji","eor"]`);
shouldBe(locale.hourCycle, undefined);
shouldBe(JSON.stringify(locale.hourCycles), `["h12"]`);
shouldBe(JSON.stringify(locale.numberingSystems), `["latn"]`);
shouldBe(JSON.stringify(locale.timeZones), `["Asia/Taipei"]`);
shouldBe(JSON.stringify(locale.getHourCycles()), `["h12"]`);
shouldBe(JSON.stringify(locale.getNumberingSystems()), `["latn"]`);
shouldBe(JSON.stringify(locale.getTimeZones()), `["Asia/Taipei"]`);
}
{
let locale = new Intl.Locale("zh-HK")
shouldBe(JSON.stringify(locale.calendars), `["gregory","chinese"]`);
shouldBe(JSON.stringify(locale.collations), `["stroke","big5han","gb2312","pinyin","unihan","zhuyin","emoji","eor"]`);
shouldBe(JSON.stringify(locale.getCalendars()), `["gregory","chinese"]`);
shouldBe(JSON.stringify(locale.getCollations()), `["stroke","big5han","gb2312","pinyin","unihan","zhuyin","emoji","eor"]`);
shouldBe(locale.hourCycle, undefined);
shouldBe(JSON.stringify(locale.hourCycles), `["h12"]`);
shouldBe(JSON.stringify(locale.numberingSystems), `["latn"]`);
shouldBe(JSON.stringify(locale.timeZones), `["Asia/Hong_Kong"]`);
shouldBe(JSON.stringify(locale.getHourCycles()), `["h12"]`);
shouldBe(JSON.stringify(locale.getNumberingSystems()), `["latn"]`);
shouldBe(JSON.stringify(locale.getTimeZones()), `["Asia/Hong_Kong"]`);
}
{
let locale = new Intl.Locale("fa")
shouldBe(JSON.stringify(locale.calendars), `["persian","gregory","islamic","islamic-civil","islamic-tbla"]`);
shouldBe(JSON.stringify(locale.collations), `["emoji","eor"]`);
shouldBe(JSON.stringify(locale.getCalendars()), `["persian","gregory","islamic","islamic-civil","islamic-tbla"]`);
shouldBe(JSON.stringify(locale.getCollations()), `["emoji","eor"]`);
shouldBe(locale.hourCycle, undefined);
shouldBe(JSON.stringify(locale.hourCycles), `["h23"]`);
shouldBe(JSON.stringify(locale.numberingSystems), `["arabext"]`);
shouldBe(locale.timeZones, undefined);
shouldBe(JSON.stringify(locale.getHourCycles()), `["h23"]`);
shouldBe(JSON.stringify(locale.getNumberingSystems()), `["arabext"]`);
shouldBe(locale.getTimeZones(), undefined);
}
2 changes: 1 addition & 1 deletion JSTests/stress/intl-locale-invalid-hourCycles.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function main() {
const v24 = new Intl.Locale("trimEnd", { 'numberingSystem': "foobar" });
let empty = v24.hourCycles;
let empty = v24.getHourCycles();
print(empty);
}

Expand Down
1 change: 1 addition & 0 deletions JSTests/test262/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ skip:
- decorators
- Intl.DurationFormat
- regexp-duplicate-named-groups
- Intl.Locale-info # Getters are replaced with methods.
paths:
- test/built-ins/Temporal/Calendar
- test/built-ins/Temporal/Instant/prototype/toZonedDateTime
Expand Down
Loading

0 comments on commit 7e2deb2

Please sign in to comment.