Commit 44771cbe authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Fixes Intl.DateTimeFormat hourCycle option issues.

Add bit flags to remember hourCycle
Reorder the code in JSDateTimeFormat::Initialize
Implement the hourCycle option resolutions
Fix intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle in test262

Bug: v8:7482
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: Idc136276da89b95df6ae864161b114e34f9dcae8
Reviewed-on: https://chromium-review.googlesource.com/c/1253101
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarJungshik Shin <jshin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58233}
parent b55dd17f
......@@ -2065,6 +2065,7 @@ void JSDateTimeFormat::JSDateTimeFormatVerify(Isolate* isolate) {
VerifyObjectField(isolate, kICULocaleOffset);
VerifyObjectField(isolate, kICUSimpleDateFormatOffset);
VerifyObjectField(isolate, kBoundFormatOffset);
VerifyObjectField(isolate, kFlagsOffset);
}
void JSListFormat::JSListFormatVerify(Isolate* isolate) {
......
......@@ -2037,6 +2037,7 @@ void JSDateTimeFormat::JSDateTimeFormatPrint(std::ostream& os) { // NOLINT
os << "\n - icu locale: " << Brief(icu_locale());
os << "\n - icu simple date format: " << Brief(icu_simple_date_format());
os << "\n - bound format: " << Brief(bound_format());
os << "\n - hour cycle: " << HourCycleAsString();
JSObjectPrintBody(os, *this);
}
......
......@@ -1849,5 +1849,14 @@ Maybe<Intl::MatcherOption> Intl::GetLocaleMatcher(Isolate* isolate,
{Intl::MatcherOption::kLookup, Intl::MatcherOption::kBestFit},
Intl::MatcherOption::kLookup);
}
Intl::HourCycle Intl::ToHourCycle(const std::string& hc) {
if (hc == "h11") return Intl::HourCycle::kH11;
if (hc == "h12") return Intl::HourCycle::kH12;
if (hc == "h23") return Intl::HourCycle::kH23;
if (hc == "h24") return Intl::HourCycle::kH24;
return Intl::HourCycle::kUndefined;
}
} // namespace internal
} // namespace v8
......@@ -223,6 +223,8 @@ class Intl {
// enum for "hourCycle" option: shared by Intl.Locale and Intl.DateTimeFormat.
enum class HourCycle { kH11, kH12, kH23, kH24, kUndefined };
static HourCycle ToHourCycle(const std::string& str);
// Shared function to read the "hourCycle" option.
V8_WARN_UNUSED_RESULT static Maybe<HourCycle> GetHourCycle(
Isolate* isolate, Handle<JSReceiver> options, const char* method);
......
......@@ -24,6 +24,17 @@ ACCESSORS(JSDateTimeFormat, icu_locale, Managed<icu::Locale>, kICULocaleOffset);
ACCESSORS(JSDateTimeFormat, icu_simple_date_format,
Managed<icu::SimpleDateFormat>, kICUSimpleDateFormatOffset)
ACCESSORS(JSDateTimeFormat, bound_format, Object, kBoundFormatOffset);
SMI_ACCESSORS(JSDateTimeFormat, flags, kFlagsOffset)
inline void JSDateTimeFormat::set_hour_cycle(Intl::HourCycle hour_cycle) {
int hints = flags();
hints = HourCycleBits::update(hints, hour_cycle);
set_flags(hints);
}
inline Intl::HourCycle JSDateTimeFormat::hour_cycle() const {
return HourCycleBits::decode(flags());
}
CAST_ACCESSOR2(JSDateTimeFormat);
......
This diff is collapsed.
......@@ -73,6 +73,7 @@ class JSDateTimeFormat : public JSObject {
static std::set<std::string> GetAvailableLocales();
Handle<String> HourCycleAsString() const;
DECL_CAST2(JSDateTimeFormat)
// Layout description.
......@@ -80,6 +81,7 @@ class JSDateTimeFormat : public JSObject {
V(kICULocaleOffset, kTaggedSize) \
V(kICUSimpleDateFormatOffset, kTaggedSize) \
V(kBoundFormatOffset, kTaggedSize) \
V(kFlagsOffset, kTaggedSize) \
/* Total size. */ \
V(kSize, 0)
......@@ -87,9 +89,25 @@ class JSDateTimeFormat : public JSObject {
JS_DATE_TIME_FORMAT_FIELDS)
#undef JS_DATE_TIME_FORMAT_FIELDS
inline void set_hour_cycle(Intl::HourCycle hour_cycle);
inline Intl::HourCycle hour_cycle() const;
// Bit positions in |flags|.
#define FLAGS_BIT_FIELDS(V, _) V(HourCycleBits, Intl::HourCycle, 3, _)
DEFINE_BIT_FIELDS(FLAGS_BIT_FIELDS)
#undef FLAGS_BIT_FIELDS
STATIC_ASSERT(Intl::HourCycle::kUndefined <= HourCycleBits::kMax);
STATIC_ASSERT(Intl::HourCycle::kH11 <= HourCycleBits::kMax);
STATIC_ASSERT(Intl::HourCycle::kH12 <= HourCycleBits::kMax);
STATIC_ASSERT(Intl::HourCycle::kH23 <= HourCycleBits::kMax);
STATIC_ASSERT(Intl::HourCycle::kH24 <= HourCycleBits::kMax);
DECL_ACCESSORS(icu_locale, Managed<icu::Locale>)
DECL_ACCESSORS(icu_simple_date_format, Managed<icu::SimpleDateFormat>)
DECL_ACCESSORS(bound_format, Object)
DECL_INT_ACCESSORS(flags)
DECL_PRINTER(JSDateTimeFormat)
DECL_VERIFIER(JSDateTimeFormat)
......
......@@ -677,7 +677,6 @@
# to be either marked as bugs with issues filed for them or as deliberate
# incompatibilities if the test cases turn out to be broken or ambiguous.
# Some of these are related to v8:4361 in being visible side effects from Intl.
'intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=7833
'built-ins/Atomics/wait/cannot-suspend-throws': [SKIP],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment