Commit 6e5e3b2c authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] fix formatToPart generate unit in plural if pass in plural as unit.

Bug: v8:8150
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: If2157d486ac164fcfd0efdc5469357fbad72e0de
Reviewed-on: https://chromium-review.googlesource.com/1215271
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55782}
parent a64e6b50
......@@ -181,6 +181,7 @@
V(prototype_string, "prototype") \
V(proxy_string, "proxy") \
V(Proxy_string, "Proxy") \
V(quarter_string, "quarter") \
V(query_colon_string, "(?:)") \
V(RangeError_string, "RangeError") \
V(raw_string, "raw") \
......@@ -248,6 +249,7 @@
V(values_string, "values") \
V(WeakMap_string, "WeakMap") \
V(WeakSet_string, "WeakSet") \
V(week_string, "week") \
V(weekday_string, "weekday") \
V(will_handle_string, "willHandle") \
V(word_string, "word") \
......
......@@ -213,9 +213,33 @@ Handle<String> JSRelativeTimeFormat::NumericAsString() const {
namespace {
Handle<String> UnitAsString(Isolate* isolate, URelativeDateTimeUnit unit_enum) {
Factory* factory = isolate->factory();
switch (unit_enum) {
case UDAT_REL_UNIT_SECOND:
return factory->second_string();
case UDAT_REL_UNIT_MINUTE:
return factory->minute_string();
case UDAT_REL_UNIT_HOUR:
return factory->hour_string();
case UDAT_REL_UNIT_DAY:
return factory->day_string();
case UDAT_REL_UNIT_WEEK:
return factory->week_string();
case UDAT_REL_UNIT_MONTH:
return factory->month_string();
case UDAT_REL_UNIT_QUARTER:
return factory->quarter_string();
case UDAT_REL_UNIT_YEAR:
return factory->year_string();
default:
UNREACHABLE();
}
}
MaybeHandle<JSArray> GenerateRelativeTimeFormatParts(
Isolate* isolate, icu::UnicodeString formatted,
icu::UnicodeString integer_part, Handle<String> unit) {
icu::UnicodeString integer_part, URelativeDateTimeUnit unit_enum) {
Factory* factory = isolate->factory();
Handle<JSArray> array = factory->NewJSArray(0);
int32_t found = formatted.indexOf(integer_part);
......@@ -254,6 +278,7 @@ MaybeHandle<JSArray> GenerateRelativeTimeFormatParts(
Intl::ToString(isolate, formatted, found,
found + integer_part.length()),
JSArray);
Handle<String> unit = UnitAsString(isolate, unit_enum);
Intl::AddElement(isolate, array, index++,
factory->integer_string(), // field_type_string
substring, factory->unit_string(), unit);
......@@ -383,7 +408,7 @@ MaybeHandle<Object> JSRelativeTimeFormat::Format(
Handle<JSArray> elements;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, elements,
GenerateRelativeTimeFormatParts(isolate, formatted, integer, unit),
GenerateRelativeTimeFormatParts(isolate, formatted, integer, unit_enum),
Object);
return elements;
}
......
// 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
// Check plural w/ formatToParts
// http://tc39.github.io/proposal-intl-relative-time/
let rtf = new Intl.RelativeTimeFormat();
// Test 1.4.4 Intl.RelativeTimeFormat.prototype.formatToParts( value, unit )
function verifyElement(part, expectedUnit) {
assertEquals(true, part.type == 'literal' || part.type == 'integer');
assertEquals('string', typeof part.value);
if (part.type == 'integer') {
assertEquals('string', typeof part.unit);
assertEquals(expectedUnit, part.unit);
}
};
// TODO(ftang): add "quarter" after the fix of 8151
['year', 'month', 'week', 'day', 'hour', 'minute', 'second'].forEach(
function(unit) {
rtf.formatToParts(100, unit + 's').forEach(
function(part) {
verifyElement(part, unit);
});
});
......@@ -614,9 +614,6 @@
# https://bugs.chromium.org/p/v8/issues/detail?id=8099
'intl402/NumberFormat/prototype/format/format-negative-numbers': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=8151
'intl402/RelativeTimeFormat/prototype/formatToParts/unit-plural': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=7871
'intl402/ListFormat/prototype/formatToParts/en-us-disjunction': [FAIL],
......
......@@ -289,33 +289,33 @@ KNOWN_MAPS = {
("RO_SPACE", 0x04811): (173, "ArrayBoilerplateDescriptionMap"),
("RO_SPACE", 0x04b01): (161, "InterceptorInfoMap"),
("RO_SPACE", 0x04bf9): (169, "ScriptMap"),
("RO_SPACE", 0x09cd1): (154, "AccessorInfoMap"),
("RO_SPACE", 0x09d21): (153, "AccessCheckInfoMap"),
("RO_SPACE", 0x09d71): (155, "AccessorPairMap"),
("RO_SPACE", 0x09dc1): (156, "AliasedArgumentsEntryMap"),
("RO_SPACE", 0x09e11): (157, "AllocationMementoMap"),
("RO_SPACE", 0x09e61): (158, "AsyncGeneratorRequestMap"),
("RO_SPACE", 0x09eb1): (159, "DebugInfoMap"),
("RO_SPACE", 0x09f01): (160, "FunctionTemplateInfoMap"),
("RO_SPACE", 0x09f51): (162, "InterpreterDataMap"),
("RO_SPACE", 0x09fa1): (163, "ModuleInfoEntryMap"),
("RO_SPACE", 0x09ff1): (164, "ModuleMap"),
("RO_SPACE", 0x0a041): (165, "ObjectTemplateInfoMap"),
("RO_SPACE", 0x0a091): (166, "PromiseCapabilityMap"),
("RO_SPACE", 0x0a0e1): (167, "PromiseReactionMap"),
("RO_SPACE", 0x0a131): (168, "PrototypeInfoMap"),
("RO_SPACE", 0x0a181): (170, "StackFrameInfoMap"),
("RO_SPACE", 0x0a1d1): (172, "Tuple3Map"),
("RO_SPACE", 0x0a221): (174, "WasmDebugInfoMap"),
("RO_SPACE", 0x0a271): (175, "WasmExportedFunctionDataMap"),
("RO_SPACE", 0x0a2c1): (176, "CallableTaskMap"),
("RO_SPACE", 0x0a311): (177, "CallbackTaskMap"),
("RO_SPACE", 0x0a361): (178, "PromiseFulfillReactionJobTaskMap"),
("RO_SPACE", 0x0a3b1): (179, "PromiseRejectReactionJobTaskMap"),
("RO_SPACE", 0x0a401): (180, "PromiseResolveThenableJobTaskMap"),
("RO_SPACE", 0x0a451): (181, "MicrotaskQueueMap"),
("RO_SPACE", 0x0a4a1): (182, "AllocationSiteMap"),
("RO_SPACE", 0x0a4f1): (182, "AllocationSiteMap"),
("RO_SPACE", 0x09d11): (154, "AccessorInfoMap"),
("RO_SPACE", 0x09d61): (153, "AccessCheckInfoMap"),
("RO_SPACE", 0x09db1): (155, "AccessorPairMap"),
("RO_SPACE", 0x09e01): (156, "AliasedArgumentsEntryMap"),
("RO_SPACE", 0x09e51): (157, "AllocationMementoMap"),
("RO_SPACE", 0x09ea1): (158, "AsyncGeneratorRequestMap"),
("RO_SPACE", 0x09ef1): (159, "DebugInfoMap"),
("RO_SPACE", 0x09f41): (160, "FunctionTemplateInfoMap"),
("RO_SPACE", 0x09f91): (162, "InterpreterDataMap"),
("RO_SPACE", 0x09fe1): (163, "ModuleInfoEntryMap"),
("RO_SPACE", 0x0a031): (164, "ModuleMap"),
("RO_SPACE", 0x0a081): (165, "ObjectTemplateInfoMap"),
("RO_SPACE", 0x0a0d1): (166, "PromiseCapabilityMap"),
("RO_SPACE", 0x0a121): (167, "PromiseReactionMap"),
("RO_SPACE", 0x0a171): (168, "PrototypeInfoMap"),
("RO_SPACE", 0x0a1c1): (170, "StackFrameInfoMap"),
("RO_SPACE", 0x0a211): (172, "Tuple3Map"),
("RO_SPACE", 0x0a261): (174, "WasmDebugInfoMap"),
("RO_SPACE", 0x0a2b1): (175, "WasmExportedFunctionDataMap"),
("RO_SPACE", 0x0a301): (176, "CallableTaskMap"),
("RO_SPACE", 0x0a351): (177, "CallbackTaskMap"),
("RO_SPACE", 0x0a3a1): (178, "PromiseFulfillReactionJobTaskMap"),
("RO_SPACE", 0x0a3f1): (179, "PromiseRejectReactionJobTaskMap"),
("RO_SPACE", 0x0a441): (180, "PromiseResolveThenableJobTaskMap"),
("RO_SPACE", 0x0a491): (181, "MicrotaskQueueMap"),
("RO_SPACE", 0x0a4e1): (182, "AllocationSiteMap"),
("RO_SPACE", 0x0a531): (182, "AllocationSiteMap"),
("MAP_SPACE", 0x02201): (1057, "ExternalMap"),
("MAP_SPACE", 0x02251): (1072, "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