Title: [283460] trunk
Revision
283460
Author
[email protected]
Date
2021-10-02 19:13:18 -0700 (Sat, 02 Oct 2021)

Log 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/_javascript_Core:

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):

Modified Paths

Diff

Modified: trunk/JSTests/ChangeLog (283459 => 283460)


--- trunk/JSTests/ChangeLog	2021-10-03 02:12:39 UTC (rev 283459)
+++ trunk/JSTests/ChangeLog	2021-10-03 02:13:18 UTC (rev 283460)
@@ -1,5 +1,17 @@
 2021-10-02  Yusuke Suzuki  <[email protected]>
 
+        [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.
+
+        * stress/intl-date-time-format-date-time-style-basic.js:
+        (shouldBe.JSON.stringify.o.resolvedOptions):
+        (shouldBe):
+        (shouldBe.o.format): Deleted.
+
+2021-10-02  Yusuke Suzuki  <[email protected]>
+
         Unreviewed, add reported test to our stress tests
         https://bugs.webkit.org/show_bug.cgi?id=230827
 

Modified: trunk/JSTests/stress/intl-date-time-format-date-time-style-basic.js (283459 => 283460)


--- trunk/JSTests/stress/intl-date-time-format-date-time-style-basic.js	2021-10-03 02:12:39 UTC (rev 283459)
+++ trunk/JSTests/stress/intl-date-time-format-date-time-style-basic.js	2021-10-03 02:13:18 UTC (rev 283460)
@@ -10,6 +10,7 @@
         timeZone: "UTC",
     });
     shouldBe(o.format(now), `2:31 PM`);
+    shouldBe(JSON.stringify(o.resolvedOptions()), `{"locale":"en","calendar":"gregory","numberingSystem":"latn","timeZone":"UTC","hourCycle":"h12","hour12":true,"timeStyle":"short"}`);
 }
 
 {
@@ -18,6 +19,7 @@
         timeZone: "UTC",
     });
     shouldBe(o.format(now), `6/22/20`);
+    shouldBe(JSON.stringify(o.resolvedOptions()), `{"locale":"en","calendar":"gregory","numberingSystem":"latn","timeZone":"UTC","dateStyle":"short"}`);
 }
 
 {
@@ -27,4 +29,5 @@
         timeZone: "UTC",
     });
     shouldBe(o.format(now), `6/22/20, 2:31:52 PM`);
+    shouldBe(JSON.stringify(o.resolvedOptions()), `{"locale":"en","calendar":"gregory","numberingSystem":"latn","timeZone":"UTC","hourCycle":"h12","hour12":true,"dateStyle":"short","timeStyle":"medium"}`);
 }

Modified: trunk/Source/_javascript_Core/ChangeLog (283459 => 283460)


--- trunk/Source/_javascript_Core/ChangeLog	2021-10-03 02:12:39 UTC (rev 283459)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-10-03 02:13:18 UTC (rev 283460)
@@ -1,5 +1,21 @@
 2021-10-02  Yusuke Suzuki  <[email protected]>
 
+        [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.
+
+        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):
+
+2021-10-02  Yusuke Suzuki  <[email protected]>
+
         [JSC] Enable Intl.DisplayNames without ICU version check
         https://bugs.webkit.org/show_bug.cgi?id=231122
 

Modified: trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp (283459 => 283460)


--- trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp	2021-10-03 02:12:39 UTC (rev 283459)
+++ trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp	2021-10-03 02:13:18 UTC (rev 283460)
@@ -1230,45 +1230,47 @@
         options->putDirect(vm, vm.propertyNames->hour12, jsBoolean(m_hourCycle == HourCycle::H11 || m_hourCycle == HourCycle::H12));
     }
 
-    if (m_weekday != Weekday::None)
-        options->putDirect(vm, vm.propertyNames->weekday, jsNontrivialString(vm, weekdayString(m_weekday)));
+    if (m_dateStyle == DateTimeStyle::None && m_timeStyle == DateTimeStyle::None) {
+        if (m_weekday != Weekday::None)
+            options->putDirect(vm, vm.propertyNames->weekday, jsNontrivialString(vm, weekdayString(m_weekday)));
 
-    if (m_era != Era::None)
-        options->putDirect(vm, vm.propertyNames->era, jsNontrivialString(vm, eraString(m_era)));
+        if (m_era != Era::None)
+            options->putDirect(vm, vm.propertyNames->era, jsNontrivialString(vm, eraString(m_era)));
 
-    if (m_year != Year::None)
-        options->putDirect(vm, vm.propertyNames->year, jsNontrivialString(vm, yearString(m_year)));
+        if (m_year != Year::None)
+            options->putDirect(vm, vm.propertyNames->year, jsNontrivialString(vm, yearString(m_year)));
 
-    if (m_month != Month::None)
-        options->putDirect(vm, vm.propertyNames->month, jsNontrivialString(vm, monthString(m_month)));
+        if (m_month != Month::None)
+            options->putDirect(vm, vm.propertyNames->month, jsNontrivialString(vm, monthString(m_month)));
 
-    if (m_day != Day::None)
-        options->putDirect(vm, vm.propertyNames->day, jsNontrivialString(vm, dayString(m_day)));
+        if (m_day != Day::None)
+            options->putDirect(vm, vm.propertyNames->day, jsNontrivialString(vm, dayString(m_day)));
 
-    if (m_dayPeriod != DayPeriod::None)
-        options->putDirect(vm, vm.propertyNames->dayPeriod, jsNontrivialString(vm, dayPeriodString(m_dayPeriod)));
+        if (m_dayPeriod != DayPeriod::None)
+            options->putDirect(vm, vm.propertyNames->dayPeriod, jsNontrivialString(vm, dayPeriodString(m_dayPeriod)));
 
-    if (m_hour != Hour::None)
-        options->putDirect(vm, vm.propertyNames->hour, jsNontrivialString(vm, hourString(m_hour)));
+        if (m_hour != Hour::None)
+            options->putDirect(vm, vm.propertyNames->hour, jsNontrivialString(vm, hourString(m_hour)));
 
-    if (m_minute != Minute::None)
-        options->putDirect(vm, vm.propertyNames->minute, jsNontrivialString(vm, minuteString(m_minute)));
+        if (m_minute != Minute::None)
+            options->putDirect(vm, vm.propertyNames->minute, jsNontrivialString(vm, minuteString(m_minute)));
 
-    if (m_second != Second::None)
-        options->putDirect(vm, vm.propertyNames->second, jsNontrivialString(vm, secondString(m_second)));
+        if (m_second != Second::None)
+            options->putDirect(vm, vm.propertyNames->second, jsNontrivialString(vm, secondString(m_second)));
 
-    if (m_fractionalSecondDigits)
-        options->putDirect(vm, vm.propertyNames->fractionalSecondDigits, jsNumber(m_fractionalSecondDigits));
+        if (m_fractionalSecondDigits)
+            options->putDirect(vm, vm.propertyNames->fractionalSecondDigits, jsNumber(m_fractionalSecondDigits));
 
-    if (m_timeZoneName != TimeZoneName::None)
-        options->putDirect(vm, vm.propertyNames->timeZoneName, jsNontrivialString(vm, timeZoneNameString(m_timeZoneName)));
+        if (m_timeZoneName != TimeZoneName::None)
+            options->putDirect(vm, vm.propertyNames->timeZoneName, jsNontrivialString(vm, timeZoneNameString(m_timeZoneName)));
+    } else {
+        if (m_dateStyle != DateTimeStyle::None)
+            options->putDirect(vm, vm.propertyNames->dateStyle, jsNontrivialString(vm, formatStyleString(m_dateStyle)));
 
-    if (m_dateStyle != DateTimeStyle::None)
-        options->putDirect(vm, vm.propertyNames->dateStyle, jsNontrivialString(vm, formatStyleString(m_dateStyle)));
+        if (m_timeStyle != DateTimeStyle::None)
+            options->putDirect(vm, vm.propertyNames->timeStyle, jsNontrivialString(vm, formatStyleString(m_timeStyle)));
+    }
 
-    if (m_timeStyle != DateTimeStyle::None)
-        options->putDirect(vm, vm.propertyNames->timeStyle, jsNontrivialString(vm, formatStyleString(m_timeStyle)));
-
     return options;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to