Changeset 266323 in webkit for trunk/Source/JavaScriptCore
- Timestamp:
- Aug 29, 2020, 1:32:45 AM (5 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r266322 r266323 1 2020-08-28 Yusuke Suzuki <[email protected]> 2 3 [JSC] Implement Intl.DateTimeFormat dayPeriod 4 https://bugs.webkit.org/show_bug.cgi?id=215839 5 6 Reviewed by Ross Kirsling. 7 8 This patch implements Intl.DateTimeFormat dayPeriod option[1]. We can use "narrow", "short", or "long" for dayPeriod, 9 and it determines how "AM" etc. is represented. 10 11 [1]: https://github.com/tc39/ecma402/pull/346 12 13 * builtins/DatePrototype.js: 14 (toLocaleString.toDateTimeOptionsAnyAll): 15 (toLocaleString): 16 (toLocaleTimeString.toDateTimeOptionsTimeTime): 17 (toLocaleTimeString): 18 * bytecode/BytecodeIntrinsicRegistry.cpp: 19 (JSC::BytecodeIntrinsicRegistry::BytecodeIntrinsicRegistry): 20 * bytecode/BytecodeIntrinsicRegistry.h: 21 * runtime/CommonIdentifiers.h: 22 * runtime/IntlDateTimeFormat.cpp: 23 (JSC::toDateTimeOptionsAnyDate): 24 (JSC::IntlDateTimeFormat::setFormatsFromPattern): 25 (JSC::IntlDateTimeFormat::initializeDateTimeFormat): 26 (JSC::IntlDateTimeFormat::dayPeriodString): 27 (JSC::IntlDateTimeFormat::resolvedOptions const): 28 * runtime/IntlDateTimeFormat.h: 29 * runtime/OptionsList.h: 30 1 31 2020-08-28 Yusuke Suzuki <[email protected]> 2 32 -
trunk/Source/JavaScriptCore/builtins/DatePrototype.js
r266170 r266323 47 47 options.month === @undefined && 48 48 options.day === @undefined && 49 (!@useIntlDateTimeFormatDayPeriod || options.dayPeriod === @undefined) && 49 50 options.hour === @undefined && 50 51 options.minute === @undefined && … … 163 164 // Check original instead of descendant to reduce lookups up the prototype chain. 164 165 var needsDefaults = !options || ( 166 (!@useIntlDateTimeFormatDayPeriod || options.dayPeriod === @undefined) && 165 167 options.hour === @undefined && 166 168 options.minute === @undefined && -
trunk/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.cpp
r261755 r266323 112 112 m_AsyncGeneratorSuspendReasonAwait.set(m_vm, jsNumber(static_cast<int32_t>(JSAsyncGenerator::AsyncGeneratorSuspendReason::Await))); 113 113 m_AsyncGeneratorSuspendReasonNone.set(m_vm, jsNumber(static_cast<int32_t>(JSAsyncGenerator::AsyncGeneratorSuspendReason::None))); 114 m_useIntlDateTimeFormatDayPeriod.set(m_vm, jsBoolean(Options::useIntlDateTimeFormatDayPeriod())); 114 115 } 115 116 -
trunk/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.h
r265907 r266323 152 152 macro(AsyncGeneratorSuspendReasonAwait) \ 153 153 macro(AsyncGeneratorSuspendReasonNone) \ 154 macro(useIntlDateTimeFormatDayPeriod) \ 154 155 155 156 #define JSC_COMMON_BYTECODE_INTRINSIC_CONSTANTS_CUSTOM_EACH_NAME(macro) \ -
trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.h
r266170 r266323 96 96 macro(dateStyle) \ 97 97 macro(day) \ 98 macro(dayPeriod) \ 98 99 macro(defineProperty) \ 99 100 macro(deref) \ -
trunk/Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp
r266170 r266323 249 249 // Always "any". 250 250 251 // a. For each of the property names " hour", "minute", "second", "fractionalSecondDigits":251 // a. For each of the property names ""dayPeriod", hour", "minute", "second", "fractionalSecondDigits": 252 252 // i. Let prop be the property name. 253 253 // ii. Let value be Get(options, prop). 254 254 // iii. ReturnIfAbrupt(value). 255 255 // iv. If value is not undefined, then let needDefaults be false. 256 if (Options::useIntlDateTimeFormatDayPeriod()) { 257 JSValue dayPeriod = options->get(globalObject, vm.propertyNames->dayPeriod); 258 RETURN_IF_EXCEPTION(scope, nullptr); 259 if (!dayPeriod.isUndefined()) 260 needDefaults = false; 261 } 262 256 263 JSValue hour = options->get(globalObject, vm.propertyNames->hour); 257 264 RETURN_IF_EXCEPTION(scope, nullptr); … … 379 386 m_day = Day::TwoDigit; 380 387 break; 388 case 'a': 389 case 'b': 390 case 'B': 391 if (count <= 3) 392 m_dayPeriod = DayPeriod::Short; 393 else if (count == 4) 394 m_dayPeriod = DayPeriod::Long; 395 else if (count == 5) 396 m_dayPeriod = DayPeriod::Narrow; 397 break; 381 398 case 'h': 382 399 case 'H': … … 585 602 } 586 603 604 DayPeriod dayPeriod = DayPeriod::None; 605 if (Options::useIntlDateTimeFormatDayPeriod()) { 606 dayPeriod = intlOption<DayPeriod>(globalObject, options, vm.propertyNames->dayPeriod, { { "narrow"_s, DayPeriod::Narrow }, { "short"_s, DayPeriod::Short }, { "long"_s, DayPeriod::Long } }, "dayPeriod must be \"narrow\", \"short\", or \"long\""_s, DayPeriod::None); 607 RETURN_IF_EXCEPTION(scope, void()); 608 } 609 587 610 Hour hour = intlOption<Hour>(globalObject, options, vm.propertyNames->hour, { { "2-digit"_s, Hour::TwoDigit }, { "numeric"_s, Hour::Numeric } }, "hour must be \"2-digit\" or \"numeric\""_s, Hour::None); 588 611 RETURN_IF_EXCEPTION(scope, void()); … … 608 631 } 609 632 633 if (Options::useIntlDateTimeFormatDayPeriod()) { 634 // dayPeriod must be set after setting hour. 635 // https://unicode-org.atlassian.net/browse/ICU-20731 636 switch (dayPeriod) { 637 case DayPeriod::Narrow: 638 skeletonBuilder.appendLiteral("BBBBB"); 639 break; 640 case DayPeriod::Short: 641 skeletonBuilder.append('B'); 642 break; 643 case DayPeriod::Long: 644 skeletonBuilder.appendLiteral("BBBB"); 645 break; 646 case DayPeriod::None: 647 break; 648 } 649 } 650 610 651 Minute minute = intlOption<Minute>(globalObject, options, vm.propertyNames->minute, { { "2-digit"_s, Minute::TwoDigit }, { "numeric"_s, Minute::Numeric } }, "minute must be \"2-digit\" or \"numeric\""_s, Minute::None); 611 652 RETURN_IF_EXCEPTION(scope, void()); … … 669 710 // iii. If p is not undefined, then 670 711 // 1. Throw a TypeError exception. 671 if (weekday != Weekday::None || era != Era::None || year != Year::None || month != Month::None || day != Day::None || hour != Hour::None || minute != Minute::None || second != Second::None || fractionalSecondDigits != 0 || timeZoneName != TimeZoneName::None) {712 if (weekday != Weekday::None || era != Era::None || year != Year::None || month != Month::None || day != Day::None || dayPeriod != DayPeriod::None || hour != Hour::None || minute != Minute::None || second != Second::None || fractionalSecondDigits != 0 || timeZoneName != TimeZoneName::None) { 672 713 throwTypeError(globalObject, scope, "dateStyle and timeStyle may not be used with other DateTimeFormat options"_s); 673 714 return; … … 893 934 } 894 935 936 ASCIILiteral IntlDateTimeFormat::dayPeriodString(DayPeriod dayPeriod) 937 { 938 switch (dayPeriod) { 939 case DayPeriod::Narrow: 940 return "narrow"_s; 941 case DayPeriod::Short: 942 return "short"_s; 943 case DayPeriod::Long: 944 return "long"_s; 945 case DayPeriod::None: 946 ASSERT_NOT_REACHED(); 947 return ASCIILiteral::null(); 948 } 949 ASSERT_NOT_REACHED(); 950 return ASCIILiteral::null(); 951 } 952 895 953 ASCIILiteral IntlDateTimeFormat::hourString(Hour hour) 896 954 { … … 1002 1060 if (m_day != Day::None) 1003 1061 options->putDirect(vm, vm.propertyNames->day, jsNontrivialString(vm, dayString(m_day))); 1062 1063 if (Options::useIntlDateTimeFormatDayPeriod()) { 1064 if (m_dayPeriod != DayPeriod::None) 1065 options->putDirect(vm, vm.propertyNames->dayPeriod, jsNontrivialString(vm, dayPeriodString(m_dayPeriod))); 1066 } 1004 1067 1005 1068 if (m_hour != Hour::None) -
trunk/Source/JavaScriptCore/runtime/IntlDateTimeFormat.h
r266170 r266323 82 82 enum class Month : uint8_t { None, TwoDigit, Numeric, Narrow, Short, Long }; 83 83 enum class Day : uint8_t { None, TwoDigit, Numeric }; 84 enum class DayPeriod : uint8_t { None, Narrow, Short, Long }; 84 85 enum class Hour : uint8_t { None, TwoDigit, Numeric }; 85 86 enum class Minute : uint8_t { None, TwoDigit, Numeric }; … … 94 95 static ASCIILiteral monthString(Month); 95 96 static ASCIILiteral dayString(Day); 97 static ASCIILiteral dayPeriodString(DayPeriod); 96 98 static ASCIILiteral hourString(Hour); 97 99 static ASCIILiteral minuteString(Minute); … … 118 120 Month m_month { Month::None }; 119 121 Day m_day { Day::None }; 122 DayPeriod m_dayPeriod { DayPeriod::None }; 120 123 Hour m_hour { Hour::None }; 121 124 Minute m_minute { Minute::None }; -
trunk/Source/JavaScriptCore/runtime/OptionsList.h
r266180 r266323 491 491 v(Bool, useWeakRefs, false, Normal, "Expose the WeakRef constructor.") \ 492 492 v(Bool, useBigInt, true, Normal, "If true, we will enable BigInt support.") \ 493 v(Bool, useIntlDateTimeFormatDayPeriod, false, Normal, "Expose the Intl.DateTimeFormat dayPeriod feature.") \ 493 494 v(Bool, useArrayAllocationProfiling, true, Normal, "If true, we will use our normal array allocation profiling. If false, the allocation profile will always claim to be undecided.") \ 494 495 v(Bool, forcePolyProto, false, Normal, "If true, create_this will always create an object with a poly proto structure.") \
Note:
See TracChangeset
for help on using the changeset viewer.