Commit 545f820c authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

Reland "[Intl] Fix RelativeTimeFormat fatal"

Fix the gc_stress problem in Original by moving the
NewStringFromAsciiChecked before the cast.

This is a reland of a872c393

Original change's description:
> [Intl] Fix RelativeTimeFormat fatal
>
> Intl.RelativeTimeFormat constructor crash while the locale or
> numberingSystem contains an "algorithmic" numberingSystem.
> Fix by fallback to the locale without the nu
>
> Bug: chromium:1041319
> Change-Id: Ica520e8dec6ace21264504274b92cb2c3d16286f
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2055970
> Reviewed-by: Shu-yu Guo <syg@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Commit-Queue: Frank Tang <ftang@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#66276}

Bug: chromium:1041319
Change-Id: I97563c5dbac1842a4e740e2450070471ea2681a0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2057761Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66315}
parent 3cf6472c
...@@ -132,10 +132,6 @@ MaybeHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::New( ...@@ -132,10 +132,6 @@ MaybeHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::New(
icu_locale.setUnicodeKeywordValue("nu", numbering_system_str.get(), status); icu_locale.setUnicodeKeywordValue("nu", numbering_system_str.get(), status);
CHECK(U_SUCCESS(status)); CHECK(U_SUCCESS(status));
} }
Handle<String> numbering_system_string =
isolate->factory()->NewStringFromAsciiChecked(
Intl::GetNumberingSystem(icu_locale).c_str());
// 15. Let dataLocale be r.[[DataLocale]]. // 15. Let dataLocale be r.[[DataLocale]].
// 16. Let s be ? GetOption(options, "style", "string", // 16. Let s be ? GetOption(options, "style", "string",
...@@ -165,7 +161,21 @@ MaybeHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::New( ...@@ -165,7 +161,21 @@ MaybeHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::New(
icu::NumberFormat::createInstance(icu_locale, UNUM_DECIMAL, status); icu::NumberFormat::createInstance(icu_locale, UNUM_DECIMAL, status);
if (U_FAILURE(status)) { if (U_FAILURE(status)) {
delete number_format; delete number_format;
FATAL("Failed to create ICU number format, are ICU data files missing?"); // Data build filter files excluded data in "rbnf_tree" since ECMA402 does
// not support "algorithmic" numbering systems. Therefore we may get the
// U_MISSING_RESOURCE_ERROR here. Fallback to locale without the numbering
// system and create the object again.
if (status == U_MISSING_RESOURCE_ERROR) {
status = U_ZERO_ERROR;
icu_locale.setUnicodeKeywordValue("nu", nullptr, status);
CHECK(U_SUCCESS(status));
number_format =
icu::NumberFormat::createInstance(icu_locale, UNUM_DECIMAL, status);
}
if (U_FAILURE(status)) {
delete number_format;
FATAL("Failed to create ICU number format, are ICU data files missing?");
}
} }
CHECK_NOT_NULL(number_format); CHECK_NOT_NULL(number_format);
...@@ -184,6 +194,10 @@ MaybeHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::New( ...@@ -184,6 +194,10 @@ MaybeHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::New(
} }
CHECK_NOT_NULL(icu_formatter); CHECK_NOT_NULL(icu_formatter);
Handle<String> numbering_system_string =
isolate->factory()->NewStringFromAsciiChecked(
Intl::GetNumberingSystem(icu_locale).c_str());
Handle<Managed<icu::RelativeDateTimeFormatter>> managed_formatter = Handle<Managed<icu::RelativeDateTimeFormatter>> managed_formatter =
Managed<icu::RelativeDateTimeFormatter>::FromRawPtr(isolate, 0, Managed<icu::RelativeDateTimeFormatter>::FromRawPtr(isolate, 0,
icu_formatter); icu_formatter);
...@@ -191,6 +205,7 @@ MaybeHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::New( ...@@ -191,6 +205,7 @@ MaybeHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::New(
Handle<JSRelativeTimeFormat> relative_time_format_holder = Handle<JSRelativeTimeFormat> relative_time_format_holder =
Handle<JSRelativeTimeFormat>::cast( Handle<JSRelativeTimeFormat>::cast(
isolate->factory()->NewFastOrSlowJSObjectFromMap(map)); isolate->factory()->NewFastOrSlowJSObjectFromMap(map));
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
relative_time_format_holder->set_flags(0); relative_time_format_holder->set_flags(0);
relative_time_format_holder->set_locale(*locale_str); relative_time_format_holder->set_locale(*locale_str);
......
// 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.
// Test to check "algorithmic" numbering systems stated in UTS35 but not
// mandated by ECMA402 won't crash.
// The entries which type is "algorithmic" in
// https://github.com/unicode-org/cldr/blob/master/common/supplemental/numberingSystems.xml
// These are numbering systems which is not supported in ECMA402 but we should
// not crash.
let algorithmicNumberingSystems = [
"armn",
"armnlow",
"cyrl",
"ethi",
"geor",
"grek",
"greklow",
"hanidays",
"hans",
"hansfin",
"hant",
"hantfin",
"hebr",
"jpan",
"jpanfin",
"jpanyear",
"roman",
"romanlow",
"taml",
];
for (numberingSystem of algorithmicNumberingSystems) {
let baseLocale = "en";
let locale = baseLocale + "-u-nu-" + numberingSystem;
// Ensure the creation won't crash
let rtf = new Intl.RelativeTimeFormat(locale);
let rtf2 = new Intl.RelativeTimeFormat(baseLocale, {numberingSystem});
let dtf = new Intl.DateTimeFormat(locale);
let dtf2 = new Intl.DateTimeFormat(baseLocale, {numberingSystem});
let nf = new Intl.NumberFormat(locale);
let nf2 = new Intl.NumberFormat(baseLocale, {numberingSystem});
}
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