[Intl] Implement nu/numberingSystem
Sync with latest Intl.RelativeTimeFormat spec. See https://github.com/tc39/proposal-intl-relative-time/pull/99 See https://github.com/tc39/proposal-intl-relative-time/pull/100 Bug: v8:8613 Change-Id: Icc5bb73ecf65e979abc23cc430259584a7bf4b48 Reviewed-on: https://chromium-review.googlesource.com/c/1385930 Commit-Queue: Frank Tang <ftang@chromium.org> Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org> Cr-Commit-Position: refs/heads/master@{#58607}
This commit is contained in:
parent
6bff5d7974
commit
8b16a54ff5
@ -96,7 +96,7 @@ MaybeHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::Initialize(
|
||||
// %RelativeTimeFormat%.[[RelevantExtensionKeys]], localeData).
|
||||
Intl::ResolvedLocale r =
|
||||
Intl::ResolveLocale(isolate, JSRelativeTimeFormat::GetAvailableLocales(),
|
||||
requested_locales, matcher, {});
|
||||
requested_locales, matcher, {"nu"});
|
||||
|
||||
// 9. Let locale be r.[[Locale]].
|
||||
// 10. Set relativeTimeFormat.[[Locale]] to locale.
|
||||
@ -178,6 +178,12 @@ Handle<JSObject> JSRelativeTimeFormat::ResolvedOptions(
|
||||
format_holder->StyleAsString(), NONE);
|
||||
JSObject::AddProperty(isolate, result, factory->numeric_string(),
|
||||
format_holder->NumericAsString(), NONE);
|
||||
std::string locale_str(format_holder->locale()->ToCString().get());
|
||||
icu::Locale icu_locale = Intl::CreateICULocale(locale_str);
|
||||
std::string numbering_system = Intl::GetNumberingSystem(icu_locale);
|
||||
JSObject::AddProperty(
|
||||
isolate, result, factory->numberingSystem_string(),
|
||||
factory->NewStringFromAsciiChecked(numbering_system.c_str()), NONE);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
97
test/intl/relative-time-format/resolved-options-nu.js
Normal file
97
test/intl/relative-time-format/resolved-options-nu.js
Normal file
@ -0,0 +1,97 @@
|
||||
// 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.
|
||||
|
||||
// Flags: --harmony-intl-relative-time-format
|
||||
|
||||
// For locale default the numberingSystem to 'latn'
|
||||
assertEquals(
|
||||
"latn",
|
||||
new Intl.RelativeTimeFormat("ar").resolvedOptions().numberingSystem
|
||||
);
|
||||
assertEquals(
|
||||
"latn",
|
||||
new Intl.RelativeTimeFormat("en").resolvedOptions().numberingSystem
|
||||
);
|
||||
assertEquals(
|
||||
"latn",
|
||||
new Intl.RelativeTimeFormat("fr").resolvedOptions().numberingSystem
|
||||
);
|
||||
assertEquals(
|
||||
"latn",
|
||||
new Intl.RelativeTimeFormat("hi").resolvedOptions().numberingSystem
|
||||
);
|
||||
assertEquals(
|
||||
"latn",
|
||||
new Intl.RelativeTimeFormat("th").resolvedOptions().numberingSystem
|
||||
);
|
||||
assertEquals(
|
||||
"latn",
|
||||
new Intl.RelativeTimeFormat("zh-Hant").resolvedOptions().numberingSystem
|
||||
);
|
||||
|
||||
// For locale default the numberingSystem to other than 'latn'
|
||||
assertEquals(
|
||||
"arab",
|
||||
new Intl.RelativeTimeFormat("ar-TD").resolvedOptions().numberingSystem
|
||||
);
|
||||
assertEquals(
|
||||
"arabext",
|
||||
new Intl.RelativeTimeFormat("fa").resolvedOptions().numberingSystem
|
||||
);
|
||||
assertEquals(
|
||||
"beng",
|
||||
new Intl.RelativeTimeFormat("bn").resolvedOptions().numberingSystem
|
||||
);
|
||||
|
||||
// For locale use -u-nu- to change to other numberingSystem
|
||||
assertEquals(
|
||||
"thai",
|
||||
new Intl.RelativeTimeFormat("en-u-nu-thai").resolvedOptions()
|
||||
.numberingSystem
|
||||
);
|
||||
assertEquals(
|
||||
"arab",
|
||||
new Intl.RelativeTimeFormat("en-u-nu-arab").resolvedOptions()
|
||||
.numberingSystem
|
||||
);
|
||||
|
||||
// For locale which default others but use -u-nu-latn to change to 'latn' numberingSystem
|
||||
assertEquals(
|
||||
"latn",
|
||||
new Intl.RelativeTimeFormat("fa-u-nu-latn").resolvedOptions()
|
||||
.numberingSystem
|
||||
);
|
||||
assertEquals(
|
||||
"latn",
|
||||
new Intl.RelativeTimeFormat("ar-TD-u-nu-latn").resolvedOptions()
|
||||
.numberingSystem
|
||||
);
|
||||
assertEquals(
|
||||
"latn",
|
||||
new Intl.RelativeTimeFormat("fa-u-nu-latn").resolvedOptions()
|
||||
.numberingSystem
|
||||
);
|
||||
assertEquals(
|
||||
"latn",
|
||||
new Intl.RelativeTimeFormat("bn-u-nu-latn").resolvedOptions()
|
||||
.numberingSystem
|
||||
);
|
||||
|
||||
// For locale use -u-nu- with invalid value still back to default.
|
||||
assertEquals(
|
||||
"latn",
|
||||
new Intl.RelativeTimeFormat("en-u-nu-abcd").resolvedOptions()
|
||||
.numberingSystem
|
||||
);
|
||||
|
||||
assertEquals(
|
||||
"arabext",
|
||||
new Intl.RelativeTimeFormat("fa-u-nu-abcd").resolvedOptions()
|
||||
.numberingSystem
|
||||
);
|
||||
assertEquals(
|
||||
"beng",
|
||||
new Intl.RelativeTimeFormat("bn-u-nu-abcd").resolvedOptions()
|
||||
.numberingSystem
|
||||
);
|
@ -13,10 +13,15 @@ assertEquals('long', rtf.resolvedOptions().style);
|
||||
assertEquals('always', rtf.resolvedOptions().numeric);
|
||||
|
||||
// contains style, numeric and locale key
|
||||
assertEquals(3, Object.getOwnPropertyNames(rtf.resolvedOptions()).length);
|
||||
assertEquals(4, Object.getOwnPropertyNames(rtf.resolvedOptions()).length);
|
||||
|
||||
// contains style, numeric and locale key
|
||||
assertEquals(3, Object.getOwnPropertyNames(new Intl.RelativeTimeFormat('en').resolvedOptions()).length);
|
||||
assertEquals(
|
||||
4,
|
||||
Object.getOwnPropertyNames(
|
||||
new Intl.RelativeTimeFormat("en").resolvedOptions()
|
||||
).length
|
||||
);
|
||||
|
||||
assertEquals(
|
||||
'short',
|
||||
|
@ -575,6 +575,9 @@
|
||||
'intl402/Locale/getters-grandfathered': [FAIL],
|
||||
'intl402/Locale/likely-subtags-grandfathered': [FAIL],
|
||||
|
||||
# https://bugs.chromium.org/p/v8/issues/detail?id=8613
|
||||
'intl402/RelativeTimeFormat/prototype/resolvedOptions/order': [FAIL],
|
||||
|
||||
# https://bugs.chromium.org/p/v8/issues/detail?id=6705
|
||||
'built-ins/Object/assign/strings-and-symbol-order': [FAIL],
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user