Commit 7552efaa authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Intl.ListFromat - add resolvedOptions().

Spec: http://tc39.github.io/proposal-intl-list-format/
Design Doc:  go/add-intl.listformat-to-v8

Test: intl/list-format/*

R=gsathya@chromium.org, mvstanton@chromium.org

Bug: v8:7871
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: I87cd84e0cabdf90adaa1486dccd9d2bee14e261d
Reviewed-on: https://chromium-review.googlesource.com/1126179Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54673}
parent 770eafd4
......@@ -4539,6 +4539,10 @@ void Genesis::InitializeGlobal_harmony_intl_list_format() {
JSObject::AddProperty(isolate(), prototype, factory()->to_string_tag_symbol(),
factory()->Object_string(),
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
SimpleInstallFunction(isolate(), prototype, "resolvedOptions",
Builtins::kListFormatPrototypeResolvedOptions, 0,
false);
}
void Genesis::InitializeGlobal_harmony_locale() {
......
......@@ -1335,8 +1335,10 @@ namespace internal {
/* ecma402 #sec-intl.datetimeformat.prototype.formattoparts */ \
CPP(DateTimeFormatPrototypeFormatToParts) \
/* ecma402 #new proposal */ \
/* ecma402 #sec-intl-list-format-constructor */ \
/* ecma402 #sec-intl-listformat-constructor */ \
CPP(ListFormatConstructor) \
/* ecma402 #sec-intl.listformat.prototype.resolvedoptions */ \
CPP(ListFormatPrototypeResolvedOptions) \
/* ecma402 #sec-intl-locale-constructor */ \
CPP(LocaleConstructor) \
CPP(LocalePrototypeLanguage) \
......
......@@ -654,6 +654,13 @@ BUILTIN(ListFormatConstructor) {
isolate, format, locales, options));
}
BUILTIN(ListFormatPrototypeResolvedOptions) {
HandleScope scope(isolate);
CHECK_RECEIVER(JSListFormat, format_holder,
"Intl.ListFormat.prototype.resolvedOptions");
return *JSListFormat::ResolvedOptions(isolate, format_holder);
}
namespace {
MaybeHandle<JSLocale> CreateLocale(Isolate* isolate,
......
// 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-list-format
let listFormat = new Intl.ListFormat();
// The default style is 'long'
assertEquals('long', listFormat.resolvedOptions().style);
// The default type is 'conjunction'
assertEquals('conjunction', listFormat.resolvedOptions().type);
assertEquals(
'short',
(new Intl.ListFormat(['sr'], {style: 'short'}))
.resolvedOptions().style);
assertEquals(
'conjunction',
(new Intl.ListFormat(['sr'], {style: 'short'}))
.resolvedOptions().type);
assertEquals(
'narrow',
(new Intl.ListFormat(['sr'], {style: 'narrow'}))
.resolvedOptions().style);
assertEquals(
'conjunction',
(new Intl.ListFormat(['sr'], {style: 'narrow'}))
.resolvedOptions().type);
assertEquals(
'long',
(new Intl.ListFormat(['sr'], {style: 'long'}))
.resolvedOptions().style);
assertEquals(
'conjunction',
(new Intl.ListFormat(['sr'], {style: 'long'}))
.resolvedOptions().type);
assertEquals(
'conjunction',
(new Intl.ListFormat(['sr'], {type: 'conjunction'}))
.resolvedOptions().type);
assertEquals(
'long',
(new Intl.ListFormat(['sr'], {type: 'conjunction'}))
.resolvedOptions().style);
assertEquals(
'disjunction',
(new Intl.ListFormat(['sr'], {type: 'disjunction'}))
.resolvedOptions().type);
assertEquals(
'long',
(new Intl.ListFormat(['sr'], {type: 'disjunction'}))
.resolvedOptions().style);
assertEquals(
'unit',
(new Intl.ListFormat(['sr'], {type: 'unit'}))
.resolvedOptions().type);
assertEquals(
'long',
(new Intl.ListFormat(['sr'], {type: 'unit'}))
.resolvedOptions().style);
assertEquals(
'disjunction',
(new Intl.ListFormat(['sr'], {style: 'long', type: 'disjunction'}))
.resolvedOptions().type);
assertEquals(
'long',
(new Intl.ListFormat(['sr'], {style: 'long', type: 'disjunction'}))
.resolvedOptions().style);
assertEquals(
'disjunction',
(new Intl.ListFormat(['sr'], {style: 'short', type: 'disjunction'}))
.resolvedOptions().type);
assertEquals(
'short',
(new Intl.ListFormat(['sr'], {style: 'short', type: 'disjunction'}))
.resolvedOptions().style);
assertEquals(
'disjunction',
(new Intl.ListFormat(['sr'], {style: 'narrow', type: 'disjunction'}))
.resolvedOptions().type);
assertEquals(
'narrow',
(new Intl.ListFormat(['sr'], {style: 'narrow', type: 'disjunction'}))
.resolvedOptions().style);
assertEquals(
'unit',
(new Intl.ListFormat(['sr'], {style: 'long', type: 'unit'}))
.resolvedOptions().type);
assertEquals(
'long',
(new Intl.ListFormat(['sr'], {style: 'long', type: 'unit'}))
.resolvedOptions().style);
assertEquals(
'unit',
(new Intl.ListFormat(['sr'], {style: 'short', type: 'unit'}))
.resolvedOptions().type);
assertEquals(
'short',
(new Intl.ListFormat(['sr'], {style: 'short', type: 'unit'}))
.resolvedOptions().style);
assertEquals(
'unit',
(new Intl.ListFormat(['sr'], {style: 'narrow', type: 'unit'}))
.resolvedOptions().type);
assertEquals(
'narrow',
(new Intl.ListFormat(['sr'], {style: 'narrow', type: 'unit'}))
.resolvedOptions().style);
assertEquals(
'ar',
(new Intl.ListFormat(['ar'])).resolvedOptions().locale);
assertEquals(
'ar',
(new Intl.ListFormat(['ar', 'en'])).resolvedOptions().locale);
assertEquals(
'fr',
(new Intl.ListFormat(['fr', 'en'])).resolvedOptions().locale);
assertEquals(
'ar',
(new Intl.ListFormat(['xyz', 'ar'])).resolvedOptions().locale);
// The following is not working yet because it depend on the getAvailableLocales
// work in another path set.
// TODO(ftang): uncomment the following once that patchset is checked in.
// assertEquals(
// 'ar',
// (new Intl.ListFormat(['i-default', 'ar'])).resolvedOptions().locale);
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