[Intl] Only set HourCycle if needed

* Change the logic to reflect the spec change of
  https://github.com/tc39/proposal-intl-datetime-style/pull/37/
* Move enum value of kUndefined to 0 to make unset behavior the same as
  kUndefined.
* Change the expectation of existing tests
* Additional tests - https://github.com/tc39/test262/pull/2385

Bug: v8:9826
Change-Id: Ic437b5f6414aa641ae73766d8c5fd5b9d352a230
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1846722
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64255}
This commit is contained in:
Frank Tang 2019-10-08 11:24:26 -07:00 committed by Commit Bot
parent a2cf979020
commit 4c1e09a4e9
3 changed files with 7 additions and 5 deletions

View File

@ -240,14 +240,14 @@ class Intl {
Handle<JSFunction> constructor, bool has_initialized_slot);
// enum for "caseFirst" option: shared by Intl.Locale and Intl.Collator.
enum class CaseFirst { kUpper, kLower, kFalse, kUndefined };
enum class CaseFirst { kUndefined, kUpper, kLower, kFalse };
// Shared function to read the "caseFirst" option.
V8_WARN_UNUSED_RESULT static Maybe<CaseFirst> GetCaseFirst(
Isolate* isolate, Handle<JSReceiver> options, const char* method);
// enum for "hourCycle" option: shared by Intl.Locale and Intl.DateTimeFormat.
enum class HourCycle { kH11, kH12, kH23, kH24, kUndefined };
enum class HourCycle { kUndefined, kH11, kH12, kH23, kH24 };
static HourCycle ToHourCycle(const std::string& str);

View File

@ -1546,12 +1546,16 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::New(
isolate->factory()->NewFastOrSlowJSObjectFromMap(map));
DisallowHeapAllocation no_gc;
date_time_format->set_flags(0);
date_time_format->set_hour_cycle(hc);
if (date_style != DateTimeStyle::kUndefined) {
date_time_format->set_date_style(date_style);
}
if (time_style != DateTimeStyle::kUndefined) {
date_time_format->set_time_style(time_style);
date_time_format->set_hour_cycle(hc);
}
if ((date_style == DateTimeStyle::kUndefined) &&
(time_style == DateTimeStyle::kUndefined)) {
date_time_format->set_hour_cycle(hc);
}
date_time_format->set_icu_locale(*managed_locale);
date_time_format->set_icu_simple_date_format(*managed_format);

View File

@ -32,8 +32,6 @@ var expectedProperties = [
'calendar',
'numberingSystem',
'timeZone',
'hourCycle',
'hour12',
'dateStyle',
];