Changeset 282257 in webkit
- Timestamp:
- Sep 9, 2021 8:23:20 PM (10 months ago)
- Location:
- trunk
- Files:
-
- 6 edited
-
JSTests/ChangeLog (modified) (1 diff)
-
JSTests/stress/intl-locale-info.js (modified) (1 diff)
-
JSTests/test262/config.yaml (modified) (1 diff)
-
Source/JavaScriptCore/ChangeLog (modified) (1 diff)
-
Source/JavaScriptCore/runtime/IntlLocale.cpp (modified) (2 diffs)
-
Source/JavaScriptCore/runtime/IntlObjectInlines.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r282239 r282257 1 2021-09-09 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [JSC] Intl.Locale weekendInfo should list all weekend days instead of range 4 https://bugs.webkit.org/show_bug.cgi?id=230108 5 6 Reviewed by Ross Kirsling. 7 8 * stress/intl-locale-info.js: 9 (throw.new.Error): 10 (let.enGB.new.Intl.Locale.shouldBe): Deleted. 11 * test262/config.yaml: 12 1 13 2021-09-09 Yusuke Suzuki <ysuzuki@apple.com> 2 14 -
trunk/JSTests/stress/intl-locale-info.js
r281513 r282257 6 6 { 7 7 let he = new Intl.Locale("he") 8 shouldBe(JSON.stringify(he.weekInfo), `{"firstDay":7,"weekend Start":5,"weekendEnd":6,"minimalDays":1}`);8 shouldBe(JSON.stringify(he.weekInfo), `{"firstDay":7,"weekend":[5,6],"minimalDays":1}`); 9 9 let af = new Intl.Locale("af") 10 shouldBe(JSON.stringify(af.weekInfo), `{"firstDay":7,"weekend Start":6,"weekendEnd":7,"minimalDays":1}`);10 shouldBe(JSON.stringify(af.weekInfo), `{"firstDay":7,"weekend":[6,7],"minimalDays":1}`); 11 11 let enGB = new Intl.Locale("en-GB") 12 shouldBe(JSON.stringify(enGB.weekInfo), `{"firstDay":1,"weekendStart":6,"weekendEnd":7,"minimalDays":4}`); 12 shouldBe(JSON.stringify(enGB.weekInfo), `{"firstDay":1,"weekend":[6,7],"minimalDays":4}`); 13 let msBN = new Intl.Locale("ms-BN"); 14 // "weekend" should be [5,7]. But currently ICU/CLDR does not support representing non-contiguous weekend. 15 shouldBe(JSON.stringify(msBN.weekInfo), `{"firstDay":1,"weekend":[6,7],"minimalDays":1}`); 13 16 } 14 17 { -
trunk/JSTests/test262/config.yaml
r282125 r282257 72 72 - test/intl402/Locale/constructor-non-iana-canon.js 73 73 - test/intl402/Locale/likely-subtags.js 74 75 # The spec is changed, but the test is not updated yet. https://github.com/tc39/proposal-intl-locale-info/pull/44 76 - test/intl402/Locale/prototype/weekInfo/output-object-keys.js 74 77 75 78 # Pass only in ICU 68~ -
trunk/Source/JavaScriptCore/ChangeLog
r282242 r282257 1 2021-09-09 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [JSC] Intl.Locale weekendInfo should list all weekend days instead of range 4 https://bugs.webkit.org/show_bug.cgi?id=230108 5 6 Reviewed by Ross Kirsling. 7 8 We cannot assume that weekend is contiguous. For example, Burnei's weekend is Friday and Sunday. 9 This is raised in [1], and our conclusion in Sep-9 meeting is that we should have an array which 10 includes all the weekend days. The change is merged in [2], and this patch changes our implementation 11 accordingly. 12 13 [1]: https://github.com/tc39/proposal-intl-locale-info/issues/25 14 [2]: https://github.com/tc39/proposal-intl-locale-info/commit/afb1e269dd698476a2514129235cdad88af60e6f 15 16 * runtime/IntlLocale.cpp: 17 (JSC::IntlLocale::weekInfo): 18 * runtime/IntlObjectInlines.h: 19 (JSC::createArrayFromIntVector): 20 1 21 2021-09-09 Darin Adler <darin@apple.com> 2 22 -
trunk/Source/JavaScriptCore/runtime/IntlLocale.cpp
r281688 r282257 793 793 }; 794 794 795 static_assert(UCAL_SUNDAY == 1); 796 static_assert(UCAL_SATURDAY == 7); 797 UCalendarWeekdayType previous = canonicalizeDayOfWeekType(ucal_getDayOfWeekType(calendar.get(), UCAL_SATURDAY, &status)); 798 if (!U_SUCCESS(status)) { 799 throwTypeError(globalObject, scope, "invalid locale"_s); 800 return nullptr; 801 } 802 803 int32_t weekendStart = 0; 804 int32_t weekendEnd = 0; 805 for (int32_t day = UCAL_SUNDAY; day <= UCAL_SATURDAY; ++day) { 806 UCalendarWeekdayType type = canonicalizeDayOfWeekType(ucal_getDayOfWeekType(calendar.get(), static_cast<UCalendarDaysOfWeek>(day), &status)); 807 if (!U_SUCCESS(status)) { 808 throwTypeError(globalObject, scope, "invalid locale"_s); 809 return nullptr; 810 } 811 if (previous != type) { 812 switch (type) { 813 case UCAL_WEEKDAY: // WeekEnd => WeekDay 814 if (day == UCAL_SUNDAY) 815 weekendEnd = UCAL_SATURDAY; 816 else 817 weekendEnd = day - 1; 818 break; 819 case UCAL_WEEKEND: // WeekDay => WeekEnd 820 weekendStart = day; 821 break; 822 default: 823 ASSERT_NOT_REACHED(); 824 break; 825 } 826 } 827 previous = type; 828 } 795 auto convertMondayBasedDayToUCalendarDaysOfWeek = [](int32_t day) -> UCalendarDaysOfWeek { 796 // Convert from 797 // Monday => 1 798 // Sunday => 7 799 // to 800 // Sunday => 1 801 // Saturday => 7 802 static_assert(UCAL_SUNDAY == 1); 803 static_assert(UCAL_SATURDAY == 7); 804 if (day == 7) 805 return UCAL_SUNDAY; 806 return static_cast<UCalendarDaysOfWeek>(day + 1); 807 }; 829 808 830 809 auto convertUCalendarDaysOfWeekToMondayBasedDay = [](int32_t day) -> int32_t { … … 840 819 }; 841 820 821 Vector<int32_t, 7> weekend; 822 for (int32_t day = 1; day <= 7; ++day) { 823 UCalendarWeekdayType type = canonicalizeDayOfWeekType(ucal_getDayOfWeekType(calendar.get(), convertMondayBasedDayToUCalendarDaysOfWeek(day), &status)); 824 if (!U_SUCCESS(status)) { 825 throwTypeError(globalObject, scope, "invalid locale"_s); 826 return nullptr; 827 } 828 switch (type) { 829 case UCAL_WEEKDAY: 830 break; 831 case UCAL_WEEKEND: 832 weekend.append(day); 833 break; 834 default: 835 ASSERT_NOT_REACHED(); 836 break; 837 } 838 } 839 840 auto* weekendArray = createArrayFromIntVector(globalObject, WTFMove(weekend)); 841 RETURN_IF_EXCEPTION(scope, { }); 842 842 843 JSObject* result = constructEmptyObject(globalObject); 843 844 result->putDirect(vm, Identifier::fromString(vm, "firstDay"), jsNumber(convertUCalendarDaysOfWeekToMondayBasedDay(firstDayOfWeek))); 844 result->putDirect(vm, Identifier::fromString(vm, "weekendStart"), jsNumber(convertUCalendarDaysOfWeekToMondayBasedDay(weekendStart))); 845 result->putDirect(vm, Identifier::fromString(vm, "weekendEnd"), jsNumber(convertUCalendarDaysOfWeekToMondayBasedDay(weekendEnd))); 845 result->putDirect(vm, Identifier::fromString(vm, "weekend"), weekendArray); 846 846 result->putDirect(vm, Identifier::fromString(vm, "minimalDays"), jsNumber(minimalDays)); 847 847 return result; -
trunk/Source/JavaScriptCore/runtime/IntlObjectInlines.h
r281788 r282257 244 244 } 245 245 246 template<typename Container> 247 JSArray* createArrayFromIntVector(JSGlobalObject* globalObject, const Container& elements) 248 { 249 VM& vm = globalObject->vm(); 250 auto scope = DECLARE_THROW_SCOPE(vm); 251 252 JSArray* result = JSArray::tryCreate(vm, globalObject->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous), elements.size()); 253 if (!result) { 254 throwOutOfMemoryError(globalObject, scope); 255 return nullptr; 256 } 257 for (unsigned index = 0; index < elements.size(); ++index) { 258 result->putDirectIndex(globalObject, index, jsNumber(elements[index])); 259 RETURN_IF_EXCEPTION(scope, { }); 260 } 261 return result; 262 } 263 246 264 } // namespace JSC
Note: See TracChangeset
for help on using the changeset viewer.