Changeset 283460 in webkit


Ignore:
Timestamp:
Oct 2, 2021 7:13:18 PM (10 months ago)
Author:
ysuzuki@apple.com
Message:

[JSC] DateTimeFormat.resolvedOptions shouldn't return an object with other date/time properties if dateStyle or timeStyle are set
https://bugs.webkit.org/show_bug.cgi?id=231041

Reviewed by Ross Kirsling.

JSTests:

  • stress/intl-date-time-format-date-time-style-basic.js:

(shouldBe.JSON.stringify.o.resolvedOptions):
(shouldBe):
(shouldBe.o.format): Deleted.

Source/JavaScriptCore:

When "dateStyle" or "timestyle" option is specified in Intl.DateTimeFormat, we should not expose detailed
resolved format information in resolvedOptions, since specifying these options is not what the user of
this Intl.DateTimeFormat intended. This is specified in the spec[1] step 5-d.

[1]: https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype.resolvedoptions

  • runtime/IntlDateTimeFormat.cpp:

(JSC::IntlDateTimeFormat::resolvedOptions const):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r283446 r283460  
     12021-10-02  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] DateTimeFormat.resolvedOptions shouldn't return an object with other date/time properties if dateStyle or timeStyle are set
     4        https://bugs.webkit.org/show_bug.cgi?id=231041
     5
     6        Reviewed by Ross Kirsling.
     7
     8        * stress/intl-date-time-format-date-time-style-basic.js:
     9        (shouldBe.JSON.stringify.o.resolvedOptions):
     10        (shouldBe):
     11        (shouldBe.o.format): Deleted.
     12
    1132021-10-02  Yusuke Suzuki  <ysuzuki@apple.com>
    214
  • trunk/JSTests/stress/intl-date-time-format-date-time-style-basic.js

    r266035 r283460  
    1111    });
    1212    shouldBe(o.format(now), `2:31 PM`);
     13    shouldBe(JSON.stringify(o.resolvedOptions()), `{"locale":"en","calendar":"gregory","numberingSystem":"latn","timeZone":"UTC","hourCycle":"h12","hour12":true,"timeStyle":"short"}`);
    1314}
    1415
     
    1920    });
    2021    shouldBe(o.format(now), `6/22/20`);
     22    shouldBe(JSON.stringify(o.resolvedOptions()), `{"locale":"en","calendar":"gregory","numberingSystem":"latn","timeZone":"UTC","dateStyle":"short"}`);
    2123}
    2224
     
    2830    });
    2931    shouldBe(o.format(now), `6/22/20, 2:31:52 PM`);
     32    shouldBe(JSON.stringify(o.resolvedOptions()), `{"locale":"en","calendar":"gregory","numberingSystem":"latn","timeZone":"UTC","hourCycle":"h12","hour12":true,"dateStyle":"short","timeStyle":"medium"}`);
    3033}
  • trunk/Source/JavaScriptCore/ChangeLog

    r283459 r283460  
     12021-10-02  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] DateTimeFormat.resolvedOptions shouldn't return an object with other date/time properties if dateStyle or timeStyle are set
     4        https://bugs.webkit.org/show_bug.cgi?id=231041
     5
     6        Reviewed by Ross Kirsling.
     7
     8        When "dateStyle" or "timestyle" option is specified in Intl.DateTimeFormat, we should not expose detailed
     9        resolved format information in resolvedOptions, since specifying these options is not what the user of
     10        this Intl.DateTimeFormat intended. This is specified in the spec[1] step 5-d.
     11
     12        [1]: https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype.resolvedoptions
     13
     14        * runtime/IntlDateTimeFormat.cpp:
     15        (JSC::IntlDateTimeFormat::resolvedOptions const):
     16
    1172021-10-02  Yusuke Suzuki  <ysuzuki@apple.com>
    218
  • trunk/Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp

    r282242 r283460  
    12311231    }
    12321232
    1233     if (m_weekday != Weekday::None)
    1234         options->putDirect(vm, vm.propertyNames->weekday, jsNontrivialString(vm, weekdayString(m_weekday)));
    1235 
    1236     if (m_era != Era::None)
    1237         options->putDirect(vm, vm.propertyNames->era, jsNontrivialString(vm, eraString(m_era)));
    1238 
    1239     if (m_year != Year::None)
    1240         options->putDirect(vm, vm.propertyNames->year, jsNontrivialString(vm, yearString(m_year)));
    1241 
    1242     if (m_month != Month::None)
    1243         options->putDirect(vm, vm.propertyNames->month, jsNontrivialString(vm, monthString(m_month)));
    1244 
    1245     if (m_day != Day::None)
    1246         options->putDirect(vm, vm.propertyNames->day, jsNontrivialString(vm, dayString(m_day)));
    1247 
    1248     if (m_dayPeriod != DayPeriod::None)
    1249         options->putDirect(vm, vm.propertyNames->dayPeriod, jsNontrivialString(vm, dayPeriodString(m_dayPeriod)));
    1250 
    1251     if (m_hour != Hour::None)
    1252         options->putDirect(vm, vm.propertyNames->hour, jsNontrivialString(vm, hourString(m_hour)));
    1253 
    1254     if (m_minute != Minute::None)
    1255         options->putDirect(vm, vm.propertyNames->minute, jsNontrivialString(vm, minuteString(m_minute)));
    1256 
    1257     if (m_second != Second::None)
    1258         options->putDirect(vm, vm.propertyNames->second, jsNontrivialString(vm, secondString(m_second)));
    1259 
    1260     if (m_fractionalSecondDigits)
    1261         options->putDirect(vm, vm.propertyNames->fractionalSecondDigits, jsNumber(m_fractionalSecondDigits));
    1262 
    1263     if (m_timeZoneName != TimeZoneName::None)
    1264         options->putDirect(vm, vm.propertyNames->timeZoneName, jsNontrivialString(vm, timeZoneNameString(m_timeZoneName)));
    1265 
    1266     if (m_dateStyle != DateTimeStyle::None)
    1267         options->putDirect(vm, vm.propertyNames->dateStyle, jsNontrivialString(vm, formatStyleString(m_dateStyle)));
    1268 
    1269     if (m_timeStyle != DateTimeStyle::None)
    1270         options->putDirect(vm, vm.propertyNames->timeStyle, jsNontrivialString(vm, formatStyleString(m_timeStyle)));
     1233    if (m_dateStyle == DateTimeStyle::None && m_timeStyle == DateTimeStyle::None) {
     1234        if (m_weekday != Weekday::None)
     1235            options->putDirect(vm, vm.propertyNames->weekday, jsNontrivialString(vm, weekdayString(m_weekday)));
     1236
     1237        if (m_era != Era::None)
     1238            options->putDirect(vm, vm.propertyNames->era, jsNontrivialString(vm, eraString(m_era)));
     1239
     1240        if (m_year != Year::None)
     1241            options->putDirect(vm, vm.propertyNames->year, jsNontrivialString(vm, yearString(m_year)));
     1242
     1243        if (m_month != Month::None)
     1244            options->putDirect(vm, vm.propertyNames->month, jsNontrivialString(vm, monthString(m_month)));
     1245
     1246        if (m_day != Day::None)
     1247            options->putDirect(vm, vm.propertyNames->day, jsNontrivialString(vm, dayString(m_day)));
     1248
     1249        if (m_dayPeriod != DayPeriod::None)
     1250            options->putDirect(vm, vm.propertyNames->dayPeriod, jsNontrivialString(vm, dayPeriodString(m_dayPeriod)));
     1251
     1252        if (m_hour != Hour::None)
     1253            options->putDirect(vm, vm.propertyNames->hour, jsNontrivialString(vm, hourString(m_hour)));
     1254
     1255        if (m_minute != Minute::None)
     1256            options->putDirect(vm, vm.propertyNames->minute, jsNontrivialString(vm, minuteString(m_minute)));
     1257
     1258        if (m_second != Second::None)
     1259            options->putDirect(vm, vm.propertyNames->second, jsNontrivialString(vm, secondString(m_second)));
     1260
     1261        if (m_fractionalSecondDigits)
     1262            options->putDirect(vm, vm.propertyNames->fractionalSecondDigits, jsNumber(m_fractionalSecondDigits));
     1263
     1264        if (m_timeZoneName != TimeZoneName::None)
     1265            options->putDirect(vm, vm.propertyNames->timeZoneName, jsNontrivialString(vm, timeZoneNameString(m_timeZoneName)));
     1266    } else {
     1267        if (m_dateStyle != DateTimeStyle::None)
     1268            options->putDirect(vm, vm.propertyNames->dateStyle, jsNontrivialString(vm, formatStyleString(m_dateStyle)));
     1269
     1270        if (m_timeStyle != DateTimeStyle::None)
     1271            options->putDirect(vm, vm.propertyNames->timeStyle, jsNontrivialString(vm, formatStyleString(m_timeStyle)));
     1272    }
    12711273
    12721274    return options;
Note: See TracChangeset for help on using the changeset viewer.