Commit 3962a0f7 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

Fix crash in dateStyle and unsupported nu

Bug: chromium:1107661
Change-Id: I6c55fb74bc009d2af2ae00e34fee9e1ee709a805
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2311352
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69009}
parent 922983df
......@@ -1317,7 +1317,7 @@ icu::UnicodeString ReplaceSkeleton(const icu::UnicodeString input,
std::unique_ptr<icu::SimpleDateFormat> DateTimeStylePattern(
JSDateTimeFormat::DateTimeStyle date_style,
JSDateTimeFormat::DateTimeStyle time_style, const icu::Locale& icu_locale,
JSDateTimeFormat::DateTimeStyle time_style, icu::Locale& icu_locale,
JSDateTimeFormat::HourCycle hc, icu::DateTimePatternGenerator* generator) {
std::unique_ptr<icu::SimpleDateFormat> result;
if (date_style != JSDateTimeFormat::DateTimeStyle::kUndefined) {
......@@ -1332,7 +1332,9 @@ std::unique_ptr<icu::SimpleDateFormat> DateTimeStylePattern(
icu_locale)));
// For instance without time, we do not need to worry about the hour cycle
// impact so we can return directly.
return result;
if (result.get() != nullptr) {
return result;
}
}
} else {
if (time_style != JSDateTimeFormat::DateTimeStyle::kUndefined) {
......@@ -1347,28 +1349,27 @@ std::unique_ptr<icu::SimpleDateFormat> DateTimeStylePattern(
UErrorCode status = U_ZERO_ERROR;
// Somehow we fail to create the instance.
if (result.get() == nullptr) {
icu::Locale modified_locale(icu_locale);
// Fallback to the locale without "nu".
if (!icu_locale.getUnicodeKeywordValue<std::string>("nu", status).empty()) {
status = U_ZERO_ERROR;
modified_locale.setUnicodeKeywordValue("nu", nullptr, status);
return DateTimeStylePattern(date_style, time_style, modified_locale, hc,
icu_locale.setUnicodeKeywordValue("nu", nullptr, status);
return DateTimeStylePattern(date_style, time_style, icu_locale, hc,
generator);
}
status = U_ZERO_ERROR;
// Fallback to the locale without "hc".
if (!icu_locale.getUnicodeKeywordValue<std::string>("hc", status).empty()) {
status = U_ZERO_ERROR;
modified_locale.setUnicodeKeywordValue("hc", nullptr, status);
return DateTimeStylePattern(date_style, time_style, modified_locale, hc,
icu_locale.setUnicodeKeywordValue("hc", nullptr, status);
return DateTimeStylePattern(date_style, time_style, icu_locale, hc,
generator);
}
status = U_ZERO_ERROR;
// Fallback to the locale without "ca".
if (!icu_locale.getUnicodeKeywordValue<std::string>("ca", status).empty()) {
status = U_ZERO_ERROR;
modified_locale.setUnicodeKeywordValue("ca", nullptr, status);
return DateTimeStylePattern(date_style, time_style, modified_locale, hc,
icu_locale.setUnicodeKeywordValue("ca", nullptr, status);
return DateTimeStylePattern(date_style, time_style, icu_locale, hc,
generator);
}
return nullptr;
......@@ -1740,6 +1741,10 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::New(
icu_date_format =
DateTimeStylePattern(date_style, time_style, icu_locale,
dateTimeFormatHourCycle, generator.get());
if (icu_date_format.get() == nullptr) {
THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kIcuError),
JSDateTimeFormat);
}
} else {
// e. If dateTimeFormat.[[Hour]] is not undefined, then
if (has_hour_option) {
......
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The following numberingSystems are not supported yet
const algorithmicNumberingSystems = [
"armn", "armnlow", "cyrl", "ethi", "geor", "grek", "greklow", "hans",
"hansfin", "hant", "hantfin", "hebr", "jpan", "jpanfin", "roman", "romanlow",
"taml"
];
algorithmicNumberingSystems.forEach(function(numberingSystem) {
let df = new Intl.DateTimeFormat("en", {dateStyle: "full", numberingSystem});
assertEquals("latn", df.resolvedOptions().numberingSystem);
let df2 = new Intl.DateTimeFormat("en-u-nu-" + numberingSystem,
{dateStyle: "full"});
assertEquals("latn", df2.resolvedOptions().numberingSystem);
// Just verify it won't crash
(new Date()).toLocaleString("en-u-nu-" + numberingSystem, {dateStyle: "full"});
});
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