Commit dfe37934 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

Revert "[Intl] Fix RelativeTimeFormat fatal"

This reverts commit a872c393.

Reason for revert: break gc_stress

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}

TBR=jkummerow@chromium.org,ftang@chromium.org,syg@chromium.org

Change-Id: I2ccfda197103d7de37d704494eb03fbe9e51ccea
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: chromium:1041319
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2057760Reviewed-by: 's avatarFrank Tang <ftang@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66277}
parent a872c393
...@@ -132,6 +132,10 @@ MaybeHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::New( ...@@ -132,6 +132,10 @@ 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",
...@@ -159,24 +163,10 @@ MaybeHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::New( ...@@ -159,24 +163,10 @@ MaybeHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::New(
// ? Construct(%NumberFormat%, « nfLocale, nfOptions »). // ? Construct(%NumberFormat%, « nfLocale, nfOptions »).
icu::NumberFormat* number_format = icu::NumberFormat* number_format =
icu::NumberFormat::createInstance(icu_locale, UNUM_DECIMAL, status); icu::NumberFormat::createInstance(icu_locale, UNUM_DECIMAL, status);
if (U_FAILURE(status)) {
delete number_format;
// 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)) { if (U_FAILURE(status)) {
delete number_format; delete number_format;
FATAL("Failed to create ICU number format, are ICU data files missing?"); FATAL("Failed to create ICU number format, are ICU data files missing?");
} }
}
CHECK_NOT_NULL(number_format); CHECK_NOT_NULL(number_format);
// Change UDISPCTX_CAPITALIZATION_NONE to other values if // Change UDISPCTX_CAPITALIZATION_NONE to other values if
...@@ -201,11 +191,6 @@ MaybeHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::New( ...@@ -201,11 +191,6 @@ 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));
Handle<String> numbering_system_string =
isolate->factory()->NewStringFromAsciiChecked(
Intl::GetNumberingSystem(icu_locale).c_str());
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