Commit c0f90e59 authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

Implement DisplayNames v2

Add "calendar", and "dateTimeField"
Add option for languageDisplay

https://tc39.es/intl-displaynames-v2/
https://chromestatus.com/feature/5082027281874944
Design Doc:
https://docs.google.com/document/d/17hQz4nOC7PJYhxc_MU-BRoT6BnYGZv66XlU1iGX0ywQ/edit#

Bug: v8:11637
Change-Id: Ie7dc80d16956f0e668b11e600e47f5bafb081ff7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2924523
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75027}
parent c9b1f165
......@@ -280,7 +280,7 @@ DEFINE_BOOL(harmony_shipping, true, "enable all shipped harmony features")
#ifdef V8_INTL_SUPPORT
#define HARMONY_INPROGRESS(V) \
HARMONY_INPROGRESS_BASE(V) \
V(harmony_intl_displaynames_date_types, "Intl.DisplayNames date types")
V(harmony_intl_displaynames_v2, "Intl.DisplayNames v2")
#else
#define HARMONY_INPROGRESS(V) HARMONY_INPROGRESS_BASE(V)
#endif
......
......@@ -4417,7 +4417,7 @@ EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_error_cause)
#ifdef V8_INTL_SUPPORT
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_intl_best_fit_matcher)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_intl_displaynames_date_types)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_intl_displaynames_v2)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_intl_dateformat_day_period)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_intl_more_timezone)
#endif // V8_INTL_SUPPORT
......
......@@ -28,6 +28,7 @@
V(_, day_string, "day") \
V(_, dayPeriod_string, "dayPeriod") \
V(_, decimal_string, "decimal") \
V(_, dialect_string, "dialect") \
V(_, direction_string, "direction") \
V(_, endRange_string, "endRange") \
V(_, engineering_string, "engineering") \
......@@ -62,6 +63,7 @@
V(_, isWordLike_string, "isWordLike") \
V(_, kana_string, "kana") \
V(_, language_string, "language") \
V(_, languageDisplay_string, "languageDisplay") \
V(_, letter_string, "letter") \
V(_, list_string, "list") \
V(_, literal_string, "literal") \
......
......@@ -35,15 +35,23 @@ inline JSDisplayNames::Style JSDisplayNames::style() const {
inline void JSDisplayNames::set_fallback(Fallback fallback) {
DCHECK_GE(FallbackBit::kMax, fallback);
int hints = flags();
hints = FallbackBit::update(hints, fallback);
set_flags(hints);
set_flags(FallbackBit::update(flags(), fallback));
}
inline JSDisplayNames::Fallback JSDisplayNames::fallback() const {
return FallbackBit::decode(flags());
}
inline void JSDisplayNames::set_language_display(
LanguageDisplay language_display) {
DCHECK_GE(LanguageDisplayBit::kMax, language_display);
set_flags(LanguageDisplayBit::update(flags(), language_display));
}
inline JSDisplayNames::LanguageDisplay JSDisplayNames::language_display()
const {
return LanguageDisplayBit::decode(flags());
}
} // namespace internal
} // namespace v8
......
This diff is collapsed.
......@@ -46,6 +46,7 @@ class JSDisplayNames
Handle<String> StyleAsString() const;
Handle<String> FallbackAsString() const;
Handle<String> LanguageDisplayAsString() const;
// Style: identifying the display names style used.
//
......@@ -68,6 +69,13 @@ class JSDisplayNames
inline void set_fallback(Fallback fallback);
inline Fallback fallback() const;
enum class LanguageDisplay {
kDialect,
kStandard,
};
inline void set_language_display(LanguageDisplay language_display);
inline LanguageDisplay language_display() const;
// Bit positions in |flags|.
DEFINE_TORQUE_GENERATED_JS_DISPLAY_NAMES_FLAGS()
......@@ -76,6 +84,8 @@ class JSDisplayNames
STATIC_ASSERT(Style::kNarrow <= StyleBits::kMax);
STATIC_ASSERT(Fallback::kCode <= FallbackBit::kMax);
STATIC_ASSERT(Fallback::kNone <= FallbackBit::kMax);
STATIC_ASSERT(LanguageDisplay::kDialect <= LanguageDisplayBit::kMax);
STATIC_ASSERT(LanguageDisplay::kStandard <= LanguageDisplayBit::kMax);
DECL_ACCESSORS(internal, Managed<DisplayNamesInternal>)
......
......@@ -7,9 +7,12 @@
type JSDisplayNamesStyle extends int32 constexpr 'JSDisplayNames::Style';
type JSDisplayNamesFallback extends int32
constexpr 'JSDisplayNames::Fallback';
type JSDisplayNamesLanguageDisplay extends int32
constexpr 'JSDisplayNames::LanguageDisplay';
bitfield struct JSDisplayNamesFlags extends uint31 {
style: JSDisplayNamesStyle: 2 bit;
fallback: JSDisplayNamesFallback: 1 bit;
language_display: JSDisplayNamesLanguageDisplay: 1 bit;
}
@generateCppClass
......
// Copyright 2021 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.islamic'
// Flags: --harmony_intl_displaynames_v2
const calendars = [
'buddhist', 'chinese', 'coptic', 'dangi', 'ethioaa', 'ethiopic-amete-alem',
'ethiopic', 'gregory', 'hebrew', 'indian', 'islamic', 'islamic-umalqura',
'islamic-tbla', 'islamic-civil', 'islamic-rgsa', 'iso8601', 'japanese',
'persian', 'roc'
];
let en = new Intl.DisplayNames("en", {type: 'calendar'});
let zh = new Intl.DisplayNames("zh", {type: 'calendar'});
calendars.forEach(function(calendar) {
assertFalse(en.of(calendar) == zh.of(calendar),
calendar + ":" + en.of(calendar) + " == " +
zh.of(calendar));
});
// Copyright 2021 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_displaynames_v2
// Throws only once during construction.
// Check for all getters to prevent regression.
// Preserve the order of getter initialization.
let getCount = 0;
new Intl.DisplayNames(['en-US'], {
get localeMatcher() {
assertEquals(0, getCount++);
},
get style() {
assertEquals(1, getCount++);
},
get type() {
assertEquals(2, getCount++);
return 'language';
},
get fallback() {
assertEquals(3, getCount++);
},
get languageDisplay() {
assertEquals(4, getCount++);
},
});
assertEquals(5, getCount);
// Copyright 2021 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_displaynames_v2
assertDoesNotThrow(
() => new Intl.DisplayNames(
'sr', {type: 'calendar'}));
assertDoesNotThrow(
() => new Intl.DisplayNames(
'sr', {type: 'dateTimeField'}));
assertDoesNotThrow(
() => new Intl.DisplayNames(
'sr', {type: 'language', languageDisplay: 'standard'}));
assertDoesNotThrow(
() => new Intl.DisplayNames(
'sr', {type: 'language', languageDisplay: 'dialect'}));
// Copyright 2021 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_displaynames_v2
const dateTimeFields = [
'era', 'year', 'quarter', 'month', 'weekOfYear', 'weekday', 'day',
'dayPeriod', 'hour', 'minute', 'second', 'timeZoneName'
];
let en = new Intl.DisplayNames("en", {type: 'dateTimeField'});
let zh = new Intl.DisplayNames("zh", {type: 'dateTimeField'});
dateTimeFields.forEach(function(dateTimeField) {
assertFalse(en.of(dateTimeField) == zh.of(dateTimeField),
dateTimeField + ":" + en.of(dateTimeField) + " == " +
zh.of(dateTimeField));
});
// Copyright 2021 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_displaynames_v2
let displayNames = new Intl.DisplayNames(undefined, {type: 'language'});
// The default languageDisplay is 'dialect' if type is 'language'
assertEquals('dialect', displayNames.resolvedOptions().languageDisplay);
['region', 'script', 'calendar', 'dateTimeField', 'currency'].forEach(
function(type) {
let dn = new Intl.DisplayNames(undefined, {type});
assertEquals(undefined, dn.resolvedOptions().languageDisplay);
});
const styles = ["long", "short", "narrow"];
const types = ["calendar", "dateTimeField"];
const fallbacks = ["code", "none"];
styles.forEach(function(style) {
types.forEach(function(type) {
assertEquals(style,
(new Intl.DisplayNames(['sr'], {style, type})).resolvedOptions().style);
assertEquals(type,
(new Intl.DisplayNames(['sr'], {style, type})).resolvedOptions().type);
assertEquals(fallbacks[0],
(new Intl.DisplayNames(
['sr'], {style, type})).resolvedOptions().fallback);
fallbacks.forEach(function(fallback) {
assertEquals(style,
(new Intl.DisplayNames(
['sr'], {style, type, fallback})).resolvedOptions().style);
assertEquals(type,
(new Intl.DisplayNames(
['sr'], {style, type, fallback})).resolvedOptions().type);
assertEquals(fallback,
(new Intl.DisplayNames(
['sr'], {style, type, fallback})).resolvedOptions().fallback);
});
});
});
const languageDisplays = ["dialect", "standard"];
styles.forEach(function(style) {
let type = 'language';
languageDisplays.forEach(function(languageDisplay) {
assertEquals(style,
(new Intl.DisplayNames(['sr'], {style, type, languageDisplay}))
.resolvedOptions().style);
assertEquals(type,
(new Intl.DisplayNames(['sr'], {style, type, languageDisplay}))
.resolvedOptions().type);
assertEquals(languageDisplay,
(new Intl.DisplayNames(['sr'], {style, type, languageDisplay}))
.resolvedOptions().languageDisplay);
});
});
......@@ -329,66 +329,66 @@ KNOWN_MAPS = {
("read_only_space", 0x03215): (67, "BasicBlockCountersMarkerMap"),
("read_only_space", 0x03259): (91, "ArrayBoilerplateDescriptionMap"),
("read_only_space", 0x03359): (104, "InterceptorInfoMap"),
("read_only_space", 0x05661): (76, "PromiseFulfillReactionJobTaskMap"),
("read_only_space", 0x05689): (77, "PromiseRejectReactionJobTaskMap"),
("read_only_space", 0x056b1): (78, "CallableTaskMap"),
("read_only_space", 0x056d9): (79, "CallbackTaskMap"),
("read_only_space", 0x05701): (80, "PromiseResolveThenableJobTaskMap"),
("read_only_space", 0x05729): (83, "FunctionTemplateInfoMap"),
("read_only_space", 0x05751): (84, "ObjectTemplateInfoMap"),
("read_only_space", 0x05779): (85, "AccessCheckInfoMap"),
("read_only_space", 0x057a1): (86, "AccessorInfoMap"),
("read_only_space", 0x057c9): (87, "AccessorPairMap"),
("read_only_space", 0x057f1): (88, "AliasedArgumentsEntryMap"),
("read_only_space", 0x05819): (89, "AllocationMementoMap"),
("read_only_space", 0x05841): (92, "AsmWasmDataMap"),
("read_only_space", 0x05869): (93, "AsyncGeneratorRequestMap"),
("read_only_space", 0x05891): (94, "BaselineDataMap"),
("read_only_space", 0x058b9): (95, "BreakPointMap"),
("read_only_space", 0x058e1): (96, "BreakPointInfoMap"),
("read_only_space", 0x05909): (97, "CachedTemplateObjectMap"),
("read_only_space", 0x05931): (99, "ClassPositionsMap"),
("read_only_space", 0x05959): (100, "DebugInfoMap"),
("read_only_space", 0x05981): (103, "FunctionTemplateRareDataMap"),
("read_only_space", 0x059a9): (105, "InterpreterDataMap"),
("read_only_space", 0x059d1): (106, "ModuleRequestMap"),
("read_only_space", 0x059f9): (107, "PromiseCapabilityMap"),
("read_only_space", 0x05a21): (108, "PromiseReactionMap"),
("read_only_space", 0x05a49): (109, "PropertyDescriptorObjectMap"),
("read_only_space", 0x05a71): (110, "PrototypeInfoMap"),
("read_only_space", 0x05a99): (111, "RegExpBoilerplateDescriptionMap"),
("read_only_space", 0x05ac1): (112, "ScriptMap"),
("read_only_space", 0x05ae9): (113, "SourceTextModuleInfoEntryMap"),
("read_only_space", 0x05b11): (114, "StackFrameInfoMap"),
("read_only_space", 0x05b39): (115, "TemplateObjectDescriptionMap"),
("read_only_space", 0x05b61): (116, "Tuple2Map"),
("read_only_space", 0x05b89): (117, "WasmExceptionTagMap"),
("read_only_space", 0x05bb1): (118, "WasmIndirectFunctionTableMap"),
("read_only_space", 0x05bd9): (136, "SloppyArgumentsElementsMap"),
("read_only_space", 0x05c01): (153, "DescriptorArrayMap"),
("read_only_space", 0x05c29): (158, "UncompiledDataWithoutPreparseDataMap"),
("read_only_space", 0x05c51): (157, "UncompiledDataWithPreparseDataMap"),
("read_only_space", 0x05c79): (174, "OnHeapBasicBlockProfilerDataMap"),
("read_only_space", 0x05ca1): (170, "InternalClassMap"),
("read_only_space", 0x05cc9): (181, "SmiPairMap"),
("read_only_space", 0x05cf1): (180, "SmiBoxMap"),
("read_only_space", 0x05d19): (147, "ExportedSubClassBaseMap"),
("read_only_space", 0x05d41): (148, "ExportedSubClassMap"),
("read_only_space", 0x05d69): (68, "AbstractInternalClassSubclass1Map"),
("read_only_space", 0x05d91): (69, "AbstractInternalClassSubclass2Map"),
("read_only_space", 0x05db9): (135, "InternalClassWithSmiElementsMap"),
("read_only_space", 0x05de1): (171, "InternalClassWithStructElementsMap"),
("read_only_space", 0x05e09): (149, "ExportedSubClass2Map"),
("read_only_space", 0x05e31): (182, "SortStateMap"),
("read_only_space", 0x05e59): (90, "AllocationSiteWithWeakNextMap"),
("read_only_space", 0x05e81): (90, "AllocationSiteWithoutWeakNextMap"),
("read_only_space", 0x05ea9): (81, "LoadHandler1Map"),
("read_only_space", 0x05ed1): (81, "LoadHandler2Map"),
("read_only_space", 0x05ef9): (81, "LoadHandler3Map"),
("read_only_space", 0x05f21): (82, "StoreHandler0Map"),
("read_only_space", 0x05f49): (82, "StoreHandler1Map"),
("read_only_space", 0x05f71): (82, "StoreHandler2Map"),
("read_only_space", 0x05f99): (82, "StoreHandler3Map"),
("read_only_space", 0x05691): (76, "PromiseFulfillReactionJobTaskMap"),
("read_only_space", 0x056b9): (77, "PromiseRejectReactionJobTaskMap"),
("read_only_space", 0x056e1): (78, "CallableTaskMap"),
("read_only_space", 0x05709): (79, "CallbackTaskMap"),
("read_only_space", 0x05731): (80, "PromiseResolveThenableJobTaskMap"),
("read_only_space", 0x05759): (83, "FunctionTemplateInfoMap"),
("read_only_space", 0x05781): (84, "ObjectTemplateInfoMap"),
("read_only_space", 0x057a9): (85, "AccessCheckInfoMap"),
("read_only_space", 0x057d1): (86, "AccessorInfoMap"),
("read_only_space", 0x057f9): (87, "AccessorPairMap"),
("read_only_space", 0x05821): (88, "AliasedArgumentsEntryMap"),
("read_only_space", 0x05849): (89, "AllocationMementoMap"),
("read_only_space", 0x05871): (92, "AsmWasmDataMap"),
("read_only_space", 0x05899): (93, "AsyncGeneratorRequestMap"),
("read_only_space", 0x058c1): (94, "BaselineDataMap"),
("read_only_space", 0x058e9): (95, "BreakPointMap"),
("read_only_space", 0x05911): (96, "BreakPointInfoMap"),
("read_only_space", 0x05939): (97, "CachedTemplateObjectMap"),
("read_only_space", 0x05961): (99, "ClassPositionsMap"),
("read_only_space", 0x05989): (100, "DebugInfoMap"),
("read_only_space", 0x059b1): (103, "FunctionTemplateRareDataMap"),
("read_only_space", 0x059d9): (105, "InterpreterDataMap"),
("read_only_space", 0x05a01): (106, "ModuleRequestMap"),
("read_only_space", 0x05a29): (107, "PromiseCapabilityMap"),
("read_only_space", 0x05a51): (108, "PromiseReactionMap"),
("read_only_space", 0x05a79): (109, "PropertyDescriptorObjectMap"),
("read_only_space", 0x05aa1): (110, "PrototypeInfoMap"),
("read_only_space", 0x05ac9): (111, "RegExpBoilerplateDescriptionMap"),
("read_only_space", 0x05af1): (112, "ScriptMap"),
("read_only_space", 0x05b19): (113, "SourceTextModuleInfoEntryMap"),
("read_only_space", 0x05b41): (114, "StackFrameInfoMap"),
("read_only_space", 0x05b69): (115, "TemplateObjectDescriptionMap"),
("read_only_space", 0x05b91): (116, "Tuple2Map"),
("read_only_space", 0x05bb9): (117, "WasmExceptionTagMap"),
("read_only_space", 0x05be1): (118, "WasmIndirectFunctionTableMap"),
("read_only_space", 0x05c09): (136, "SloppyArgumentsElementsMap"),
("read_only_space", 0x05c31): (153, "DescriptorArrayMap"),
("read_only_space", 0x05c59): (158, "UncompiledDataWithoutPreparseDataMap"),
("read_only_space", 0x05c81): (157, "UncompiledDataWithPreparseDataMap"),
("read_only_space", 0x05ca9): (174, "OnHeapBasicBlockProfilerDataMap"),
("read_only_space", 0x05cd1): (170, "InternalClassMap"),
("read_only_space", 0x05cf9): (181, "SmiPairMap"),
("read_only_space", 0x05d21): (180, "SmiBoxMap"),
("read_only_space", 0x05d49): (147, "ExportedSubClassBaseMap"),
("read_only_space", 0x05d71): (148, "ExportedSubClassMap"),
("read_only_space", 0x05d99): (68, "AbstractInternalClassSubclass1Map"),
("read_only_space", 0x05dc1): (69, "AbstractInternalClassSubclass2Map"),
("read_only_space", 0x05de9): (135, "InternalClassWithSmiElementsMap"),
("read_only_space", 0x05e11): (171, "InternalClassWithStructElementsMap"),
("read_only_space", 0x05e39): (149, "ExportedSubClass2Map"),
("read_only_space", 0x05e61): (182, "SortStateMap"),
("read_only_space", 0x05e89): (90, "AllocationSiteWithWeakNextMap"),
("read_only_space", 0x05eb1): (90, "AllocationSiteWithoutWeakNextMap"),
("read_only_space", 0x05ed9): (81, "LoadHandler1Map"),
("read_only_space", 0x05f01): (81, "LoadHandler2Map"),
("read_only_space", 0x05f29): (81, "LoadHandler3Map"),
("read_only_space", 0x05f51): (82, "StoreHandler0Map"),
("read_only_space", 0x05f79): (82, "StoreHandler1Map"),
("read_only_space", 0x05fa1): (82, "StoreHandler2Map"),
("read_only_space", 0x05fc9): (82, "StoreHandler3Map"),
("map_space", 0x02119): (1057, "ExternalMap"),
("map_space", 0x02141): (1098, "JSMessageObjectMap"),
}
......
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