Commit 787cd95f authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

Fix crash bug with some numberingSystem and dateStyle/timeStyle

Bug: v8:9849
Change-Id: Ib7812e27dcacb30fd2610badbf79dee190fdec15
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1869078Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64436}
parent cdf8925e
......@@ -1152,10 +1152,40 @@ std::unique_ptr<icu::SimpleDateFormat> DateTimeStylePattern(
UNREACHABLE();
}
}
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,
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,
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,
generator);
}
return nullptr;
}
icu::UnicodeString pattern;
pattern = result->toPattern(pattern);
UErrorCode status = U_ZERO_ERROR;
status = U_ZERO_ERROR;
icu::UnicodeString skeleton =
icu::DateTimePatternGenerator::staticGetSkeleton(pattern, status);
CHECK(U_SUCCESS(status));
......
// Copyright 2019 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.
let d = new Date(271733878);
d.toLocaleString('en-u-nu-arab');
d.toLocaleString('en-u-nu-arab', {dateStyle : 'full', timeStyle : 'full'});
d.toLocaleString('en-u-nu-roman');
d.toLocaleString('en-u-nu-roman', {dateStyle : 'full', timeStyle : 'full'});
d.toLocaleString('sr-u-nu-roman');
d.toLocaleString('sr-u-nu-roman', {dateStyle : 'full', timeStyle : 'full'});
d.toLocaleString('sr-Cyrl-u-nu-roman');
d.toLocaleString('sr-Cyrl-u-nu-roman', {dateStyle : 'full', timeStyle : 'full'});
d.toLocaleString('zh-u-nu-roman', {dateStyle : 'full', timeStyle : 'full'});
d.toLocaleString('ja-u-nu-cyrl', {dateStyle : 'full', timeStyle : '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