Commit 5c7c6835 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

Sync DateTimeFormat with latest changes

https://tc39.es/proposal-intl-datetime-style/ (Jun 10, 2020)

fix extra s in message

Bug: v8:10613
Change-Id: I2ef4f4004c1e8f0a58bf4409578876d1553de59b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2242258
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68329}
parent 9d6f96c1
...@@ -320,7 +320,7 @@ namespace internal { ...@@ -320,7 +320,7 @@ namespace internal {
"a location, got %") \ "a location, got %") \
T(InvalidArrayBufferLength, "Invalid array buffer length") \ T(InvalidArrayBufferLength, "Invalid array buffer length") \
T(ArrayBufferAllocationFailed, "Array buffer allocation failed") \ T(ArrayBufferAllocationFailed, "Array buffer allocation failed") \
T(Invalid, "Invalid %s : %") \ T(Invalid, "Invalid % : %") \
T(InvalidArrayLength, "Invalid array length") \ T(InvalidArrayLength, "Invalid array length") \
T(InvalidAtomicAccessIndex, "Invalid atomic access index") \ T(InvalidAtomicAccessIndex, "Invalid atomic access index") \
T(InvalidCodePoint, "Invalid code point %") \ T(InvalidCodePoint, "Invalid code point %") \
......
This diff is collapsed.
...@@ -75,32 +75,63 @@ new Intl.DateTimeFormat(['en-US'], { ...@@ -75,32 +75,63 @@ new Intl.DateTimeFormat(['en-US'], {
} }
}); });
assertEquals(1, weekday.length); // Read by ToDateTimeOptions and also in Table 1
// https://tc39.es/proposal-intl-datetime-style/#table-datetimeformat-components
assertEquals(2, weekday.length);
assertEquals(2, year.length);
assertEquals(2, month.length);
assertEquals(2, day.length);
assertEquals(2, hour.length);
assertEquals(2, minute.length);
assertEquals(2, second.length);
// In Table 1
// https://tc39.es/proposal-intl-datetime-style/#table-datetimeformat-components
assertEquals(1, era.length);
assertEquals(1, timeZoneName.length);
// Read by ToDateTimeOptions and InitializeDateTimeFormat
assertEquals(2, dateStyle.length);
assertEquals(2, timeStyle.length);
// Only read by InitializeDateTimeFormat
assertEquals(1, localeMatcher.length);
assertEquals(1, hour12.length);
assertEquals(1, hourCycle.length);
assertEquals(1, timeZone.length);
assertEquals(1, formatMatcher.length);
// ToDateTimeOptions
assertEquals(1, weekday[0]); assertEquals(1, weekday[0]);
assertEquals(1, year.length);
assertEquals(2, year[0]); assertEquals(2, year[0]);
assertEquals(1, month.length);
assertEquals(3, month[0]); assertEquals(3, month[0]);
assertEquals(1, day.length);
assertEquals(4, day[0]); assertEquals(4, day[0]);
assertEquals(1, hour.length);
assertEquals(5, hour[0]); assertEquals(5, hour[0]);
assertEquals(1, minute.length);
assertEquals(6, minute[0]); assertEquals(6, minute[0]);
assertEquals(1, second.length);
assertEquals(7, second[0]); assertEquals(7, second[0]);
assertEquals(1, localeMatcher.length); assertEquals(8, dateStyle[0]);
assertEquals(8, localeMatcher[0]); assertEquals(9, timeStyle[0]);
assertEquals(1, hour12.length);
assertEquals(9, hour12[0]); // InitializeDateTimeFormat
assertEquals(1, hourCycle.length); assertEquals(10, localeMatcher[0]);
assertEquals(10, hourCycle[0]); assertEquals(11, hour12[0]);
assertEquals(1, timeZone.length); assertEquals(12, hourCycle[0]);
assertEquals(11, timeZone[0]); assertEquals(13, timeZone[0]);
assertEquals(1, dateStyle.length);
assertEquals(12, dateStyle[0]); // Table 1 loop in InitializeDateTimeFormat
assertEquals(1, timeStyle.length); assertEquals(14, weekday[1]);
assertEquals(13, timeStyle[0]); assertEquals(15, era[0]);
assertEquals(0, era.length); assertEquals(16, year[1]);
assertEquals(0, timeZoneName.length); assertEquals(17, month[1]);
assertEquals(0, formatMatcher.length); assertEquals(18, day[1]);
assertEquals(19, hour[1]);
assertEquals(20, minute[1]);
assertEquals(21, second[1]);
assertEquals(22, timeZoneName[0]);
// After the Table 1 loop in InitializeDateTimeFormat
assertEquals(23, formatMatcher[0]);
assertEquals(24, dateStyle[1]);
assertEquals(25, timeStyle[1]);
assertEquals(25, getCount);
...@@ -76,32 +76,63 @@ new Intl.DateTimeFormat(['en-US'], { ...@@ -76,32 +76,63 @@ new Intl.DateTimeFormat(['en-US'], {
} }
}); });
assertEquals(1, weekday.length); // Read by ToDateTimeOptions and also in Table 1
// https://tc39.es/proposal-intl-datetime-style/#table-datetimeformat-components
assertEquals(2, weekday.length);
assertEquals(2, year.length);
assertEquals(2, month.length);
assertEquals(2, day.length);
assertEquals(2, hour.length);
assertEquals(2, minute.length);
assertEquals(2, second.length);
// In Table 1
// https://tc39.es/proposal-intl-datetime-style/#table-datetimeformat-components
assertEquals(1, era.length);
assertEquals(1, timeZoneName.length);
// Read by ToDateTimeOptions and InitializeDateTimeFormat
assertEquals(2, dateStyle.length);
assertEquals(2, timeStyle.length);
// Only read by InitializeDateTimeFormat
assertEquals(1, localeMatcher.length);
assertEquals(1, hour12.length);
assertEquals(1, hourCycle.length);
assertEquals(1, timeZone.length);
assertEquals(1, formatMatcher.length);
// ToDateTimeOptions
assertEquals(1, weekday[0]); assertEquals(1, weekday[0]);
assertEquals(1, year.length);
assertEquals(2, year[0]); assertEquals(2, year[0]);
assertEquals(1, month.length);
assertEquals(3, month[0]); assertEquals(3, month[0]);
assertEquals(1, day.length);
assertEquals(4, day[0]); assertEquals(4, day[0]);
assertEquals(1, hour.length);
assertEquals(5, hour[0]); assertEquals(5, hour[0]);
assertEquals(1, minute.length);
assertEquals(6, minute[0]); assertEquals(6, minute[0]);
assertEquals(1, second.length);
assertEquals(7, second[0]); assertEquals(7, second[0]);
assertEquals(1, localeMatcher.length); assertEquals(8, dateStyle[0]);
assertEquals(8, localeMatcher[0]); assertEquals(9, timeStyle[0]);
assertEquals(1, hour12.length);
assertEquals(9, hour12[0]); // InitializeDateTimeFormat
assertEquals(1, hourCycle.length); assertEquals(10, localeMatcher[0]);
assertEquals(10, hourCycle[0]); assertEquals(11, hour12[0]);
assertEquals(1, timeZone.length); assertEquals(12, hourCycle[0]);
assertEquals(11, timeZone[0]); assertEquals(13, timeZone[0]);
assertEquals(1, dateStyle.length);
assertEquals(12, dateStyle[0]); // Table 1 loop in InitializeDateTimeFormat
assertEquals(1, timeStyle.length); assertEquals(14, weekday[1]);
assertEquals(13, timeStyle[0]); assertEquals(15, era[0]);
assertEquals(0, era.length); assertEquals(16, year[1]);
assertEquals(0, timeZoneName.length); assertEquals(17, month[1]);
assertEquals(0, formatMatcher.length); assertEquals(18, day[1]);
assertEquals(19, hour[1]);
assertEquals(20, minute[1]);
assertEquals(21, second[1]);
assertEquals(22, timeZoneName[0]);
// After the Table 1 loop in InitializeDateTimeFormat
assertEquals(23, formatMatcher[0]);
assertEquals(24, dateStyle[1]);
assertEquals(25, timeStyle[1]);
assertEquals(25, getCount);
...@@ -74,39 +74,63 @@ new Intl.DateTimeFormat(['en-US'], { ...@@ -74,39 +74,63 @@ new Intl.DateTimeFormat(['en-US'], {
} }
}); });
// Read by ToDateTimeOptions and also in Table 1
// https://tc39.es/proposal-intl-datetime-style/#table-datetimeformat-components
assertEquals(2, weekday.length); assertEquals(2, weekday.length);
assertEquals(1, weekday[0]);
assertEquals(1, year.length);
assertEquals(2, year[0]);
assertEquals(1, month.length);
assertEquals(3, month[0]);
assertEquals(1, day.length);
assertEquals(4, day[0]);
assertEquals(2, hour.length); assertEquals(2, hour.length);
assertEquals(5, hour[0]);
assertEquals(2, minute.length); assertEquals(2, minute.length);
assertEquals(6, minute[0]);
assertEquals(2, second.length); assertEquals(2, second.length);
assertEquals(7, second[0]);
// Read by ToDateTimeOptions and also overwrite with a default 'numeric'
// https://tc39.es/proposal-intl-datetime-style/#table-datetimeformat-components
assertEquals(1, year.length);
assertEquals(1, month.length);
assertEquals(1, day.length);
// In Table 1
// https://tc39.es/proposal-intl-datetime-style/#table-datetimeformat-components
assertEquals(1, era.length);
assertEquals(1, timeZoneName.length);
// Read by ToDateTimeOptions and InitializeDateTimeFormat
assertEquals(2, dateStyle.length);
assertEquals(2, timeStyle.length);
// Only read by InitializeDateTimeFormat
assertEquals(1, localeMatcher.length); assertEquals(1, localeMatcher.length);
assertEquals(8, localeMatcher[0]);
assertEquals(1, hour12.length); assertEquals(1, hour12.length);
assertEquals(9, hour12[0]);
assertEquals(1, hourCycle.length); assertEquals(1, hourCycle.length);
assertEquals(10, hourCycle[0]);
assertEquals(1, timeZone.length); assertEquals(1, timeZone.length);
assertEquals(11, timeZone[0]); assertEquals(1, formatMatcher.length);
assertEquals(1, dateStyle.length);
assertEquals(12, dateStyle[0]); // ToDateTimeOptions
assertEquals(1, timeStyle.length); assertEquals(1, weekday[0]);
assertEquals(13, timeStyle[0]); assertEquals(2, year[0]);
assertEquals(3, month[0]);
assertEquals(4, day[0]);
assertEquals(5, hour[0]);
assertEquals(6, minute[0]);
assertEquals(7, second[0]);
assertEquals(8, dateStyle[0]);
assertEquals(9, timeStyle[0]);
// InitializeDateTimeFormat
assertEquals(10, localeMatcher[0]);
assertEquals(11, hour12[0]);
assertEquals(12, hourCycle[0]);
assertEquals(13, timeZone[0]);
// Table 1 loop in InitializeDateTimeFormat
assertEquals(14, weekday[1]); assertEquals(14, weekday[1]);
assertEquals(1, era.length);
assertEquals(15, era[0]); assertEquals(15, era[0]);
assertEquals(16, hour[1]); assertEquals(16, hour[1]);
assertEquals(17, minute[1]); assertEquals(17, minute[1]);
assertEquals(18, second[1]); assertEquals(18, second[1]);
assertEquals(1, timeZoneName.length);
assertEquals(19, timeZoneName[0]); assertEquals(19, timeZoneName[0]);
assertEquals(1, formatMatcher.length);
// After the Table 1 loop in InitializeDateTimeFormat
assertEquals(20, formatMatcher[0]); assertEquals(20, formatMatcher[0]);
assertEquals(21, dateStyle[1]);
assertEquals(22, timeStyle[1]);
assertEquals(22, getCount);
...@@ -75,32 +75,63 @@ new Intl.DateTimeFormat(['en-US'], { ...@@ -75,32 +75,63 @@ new Intl.DateTimeFormat(['en-US'], {
} }
}); });
assertEquals(1, weekday.length); // Read by ToDateTimeOptions and also in Table 1
// https://tc39.es/proposal-intl-datetime-style/#table-datetimeformat-components
assertEquals(2, weekday.length);
assertEquals(2, year.length);
assertEquals(2, month.length);
assertEquals(2, day.length);
assertEquals(2, hour.length);
assertEquals(2, minute.length);
assertEquals(2, second.length);
// In Table 1
// https://tc39.es/proposal-intl-datetime-style/#table-datetimeformat-components
assertEquals(1, era.length);
assertEquals(1, timeZoneName.length);
// Read by ToDateTimeOptions and InitializeDateTimeFormat
assertEquals(2, dateStyle.length);
assertEquals(2, timeStyle.length);
// Only read by InitializeDateTimeFormat
assertEquals(1, localeMatcher.length);
assertEquals(1, hour12.length);
assertEquals(1, hourCycle.length);
assertEquals(1, timeZone.length);
assertEquals(1, formatMatcher.length);
// ToDateTimeOptions
assertEquals(1, weekday[0]); assertEquals(1, weekday[0]);
assertEquals(1, year.length);
assertEquals(2, year[0]); assertEquals(2, year[0]);
assertEquals(1, month.length);
assertEquals(3, month[0]); assertEquals(3, month[0]);
assertEquals(1, day.length);
assertEquals(4, day[0]); assertEquals(4, day[0]);
assertEquals(1, hour.length);
assertEquals(5, hour[0]); assertEquals(5, hour[0]);
assertEquals(1, minute.length);
assertEquals(6, minute[0]); assertEquals(6, minute[0]);
assertEquals(1, second.length);
assertEquals(7, second[0]); assertEquals(7, second[0]);
assertEquals(1, localeMatcher.length); assertEquals(8, dateStyle[0]);
assertEquals(8, localeMatcher[0]); assertEquals(9, timeStyle[0]);
assertEquals(1, hour12.length);
assertEquals(9, hour12[0]); // InitializeDateTimeFormat
assertEquals(1, hourCycle.length); assertEquals(10, localeMatcher[0]);
assertEquals(10, hourCycle[0]); assertEquals(11, hour12[0]);
assertEquals(1, timeZone.length); assertEquals(12, hourCycle[0]);
assertEquals(11, timeZone[0]); assertEquals(13, timeZone[0]);
assertEquals(1, dateStyle.length);
assertEquals(12, dateStyle[0]); // Table 1 loop in InitializeDateTimeFormat
assertEquals(1, timeStyle.length); assertEquals(14, weekday[1]);
assertEquals(13, timeStyle[0]); assertEquals(15, era[0]);
assertEquals(0, era.length); assertEquals(16, year[1]);
assertEquals(0, timeZoneName.length); assertEquals(17, month[1]);
assertEquals(0, formatMatcher.length); assertEquals(18, day[1]);
assertEquals(19, hour[1]);
assertEquals(20, minute[1]);
assertEquals(21, second[1]);
assertEquals(22, timeZoneName[0]);
// After the Table 1 loop in InitializeDateTimeFormat
assertEquals(23, formatMatcher[0]);
assertEquals(24, dateStyle[1]);
assertEquals(25, timeStyle[1]);
assertEquals(25, getCount);
...@@ -36,16 +36,15 @@ assertEquals( ...@@ -36,16 +36,15 @@ assertEquals(
(new Intl.DateTimeFormat("en", {fractionalSecondDigits: undefined})) (new Intl.DateTimeFormat("en", {fractionalSecondDigits: undefined}))
.resolvedOptions().fractionalSecondDigits); .resolvedOptions().fractionalSecondDigits);
// When timeStyle or dateStyle is present, the code should not read // When timeStyle or dateStyle is present, we should throw TypeError
// fractionalSecondDigits from the option. assertThrows(
assertEquals( () => (new Intl.DateTimeFormat(
undefined, "en", {timeStyle: "short", fractionalSecondDigits: 3})),
(new Intl.DateTimeFormat( TypeError,
"en", {timeStyle: "short", fractionalSecondDigits: 3})) "Invalid option : timeStyle");
.resolvedOptions().fractionalSecondDigits);
assertThrows(
assertEquals( () => (new Intl.DateTimeFormat(
undefined, "en", {dateStyle: "short", fractionalSecondDigits: 3})),
(new Intl.DateTimeFormat( TypeError,
"en", {dateStyle: "short", fractionalSecondDigits: 3})) "Invalid option : dateStyle");
.resolvedOptions().fractionalSecondDigits);
// Copyright 2020 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
// https://github.com/tc39/proposal-intl-datetime-style/pull/43
// https://github.com/tc39/proposal-intl-datetime-style/pull/47
// https://github.com/tc39/proposal-intl-datetime-style/pull/50
let opt = {
weekday: 'narrow',
era: 'narrow',
year: '2-digit',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
};
let keys = Object.keys(opt);
let testDateStyle = { ...opt };
let testTimeStyle = { ...opt };
testDateStyle.dateStyle = 'long';
testTimeStyle.timeStyle = 'long';
for (key of keys) {
assertThrows(
() => new Intl.DateTimeFormat('en', testDateStyle),
TypeError, "Invalid option : dateStyle");
assertThrows(
() => new Intl.DateTimeFormat('en', testTimeStyle),
TypeError, "Invalid option : timeStyle");
testDateStyle[key] = undefined;
testTimeStyle[key] = undefined;
}
assertThrows(
() => (new Date()).toLocaleDateString("en", {timeStyle: "long"}),
TypeError, "Invalid option : timeStyle");
assertThrows(
() => (new Date()).toLocaleTimeString("en", {dateStyle: "long"}),
TypeError, "Invalid option : dateStyle");
let logs = [];
try {
var dtf = new Intl.DateTimeFormat("en", {
get timeStyle() {
logs.push("get timeStyle");
return "full";
},
get timeZoneName() {
logs.push("get timeZoneName");
return "short";
},
});
logs.push(dtf.resolvedOptions().timeStyle);
logs.push(dtf.resolvedOptions().timeZoneName);
} catch(e) {
logs.push(e.name);
}
assertEquals(
"get timeStyle,get timeZoneName,get timeStyle,TypeError",
logs.join(','));
...@@ -602,6 +602,10 @@ ...@@ -602,6 +602,10 @@
'built-ins/Atomics/waitAsync/true-for-timeout-agent': [SKIP], 'built-ins/Atomics/waitAsync/true-for-timeout-agent': [SKIP],
'built-ins/Atomics/waitAsync/value-not-equal-agent': [SKIP], 'built-ins/Atomics/waitAsync/value-not-equal-agent': [SKIP],
# https://github.com/tc39/test262/pull/2659
'intl402/DateTimeFormat/prototype/resolvedOptions/order-style': [FAIL],
'intl402/DateTimeFormat/constructor-options-order-timedate-style': [FAIL],
######################## NEEDS INVESTIGATION ########################### ######################## NEEDS INVESTIGATION ###########################
# https://bugs.chromium.org/p/v8/issues/detail?id=7833 # https://bugs.chromium.org/p/v8/issues/detail?id=7833
......
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