diff --git a/src/objects/intl-objects.cc b/src/objects/intl-objects.cc index e32be5d155..abeeb1d24c 100644 --- a/src/objects/intl-objects.cc +++ b/src/objects/intl-objects.cc @@ -397,11 +397,8 @@ std::string Intl::GetNumberingSystem(const icu::Locale& icu_locale) { UErrorCode status = U_ZERO_ERROR; std::unique_ptr numbering_system( icu::NumberingSystem::createInstance(icu_locale, status)); - std::string value; - if (U_SUCCESS(status)) { - value = numbering_system->getName(); - } - return value; + if (U_SUCCESS(status)) return numbering_system->getName(); + return "latn"; } icu::Locale Intl::CreateICULocale(const std::string& bcp47_locale) { diff --git a/src/objects/js-number-format.cc b/src/objects/js-number-format.cc index 2562c2ceef..47d5b71e8d 100644 --- a/src/objects/js-number-format.cc +++ b/src/objects/js-number-format.cc @@ -90,9 +90,8 @@ Handle JSNumberFormat::ResolvedOptions( Handle locale = Handle(number_format_holder->locale(), isolate); - UErrorCode error = U_ZERO_ERROR; - icu::Locale icu_locale = number_format->getLocale(ULOC_VALID_LOCALE, error); - DCHECK(U_SUCCESS(error)); + std::unique_ptr locale_str = locale->ToCString(); + icu::Locale icu_locale = Intl::CreateICULocale(locale_str.get()); std::string numbering_system = Intl::GetNumberingSystem(icu_locale); diff --git a/test/intl/regress-8525.js b/test/intl/regress-8525.js new file mode 100644 index 0000000000..4d925d73c3 --- /dev/null +++ b/test/intl/regress-8525.js @@ -0,0 +1,27 @@ +// Copyright 2018 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 the numberingSystem is set correctly via -u-nu- +let dtf = new Intl.DateTimeFormat(["en-u-ba-rfoo-nu-arab-fo-obar"]); +assertEquals("arab", dtf.resolvedOptions().numberingSystem); +assertEquals("en-u-nu-arab", dtf.resolvedOptions().locale); + +let nf = new Intl.NumberFormat(["en-u-ba-rfoo-nu-arab-fo-obar"]); +assertEquals("arab", nf.resolvedOptions().numberingSystem); +assertEquals("١٢٣", nf.format(123)); +assertEquals("en-u-nu-arab", nf.resolvedOptions().locale); + +dtf = new Intl.DateTimeFormat(["en-u-ba-rfoo-nu-thai-fo-obar"]); +assertEquals("thai", dtf.resolvedOptions().numberingSystem); +assertEquals("en-u-nu-thai", dtf.resolvedOptions().locale); + +nf = new Intl.NumberFormat(["en-u-ba-rfoo-nu-thai-fo-obar"]); +assertEquals("thai", nf.resolvedOptions().numberingSystem); +assertEquals("๑๒๓", nf.format(123)); +assertEquals("en-u-nu-thai", nf.resolvedOptions().locale); + +nf = new Intl.NumberFormat(["ar-EG-u-nu-latn"]); +assertEquals("latn", nf.resolvedOptions().numberingSystem); +assertEquals("123", nf.format(123)); +assertEquals("ar-EG-u-nu-latn", nf.resolvedOptions().locale);