Commit f2974002 authored by Jungshik Shin's avatar Jungshik Shin Committed by Commit Bot

TimeClip before formatting in Intl.DateTimeFormat

https://github.com/tc39/ecma402/pull/194 requires that
TimeClip be called before formatting in Intl.DateTimeFormat.

Bug: v8:7471
Test: test262/intl402/DateTimeFormat/prototype/format/time-clip*
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: Iad80376ae7598aab3e4df84a6cbbcd8691e16e09
Reviewed-on: https://chromium-review.googlesource.com/1027442Reviewed-by: 's avatarDaniel Ehrenberg <littledan@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Jungshik Shin <jshin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52796}
parent 9a7c4bfe
......@@ -98,14 +98,6 @@ double MakeTime(double hour, double min, double sec, double ms) {
return std::numeric_limits<double>::quiet_NaN();
}
// ES6 section 20.3.1.15 TimeClip (time)
double TimeClip(double time) {
if (-DateCache::kMaxTimeInMs <= time && time <= DateCache::kMaxTimeInMs) {
return DoubleToInteger(time) + 0.0;
}
return std::numeric_limits<double>::quiet_NaN();
}
const char* kShortWeekDays[] = {"Sun", "Mon", "Tue", "Wed",
"Thu", "Fri", "Sat"};
const char* kShortMonths[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
......@@ -188,7 +180,7 @@ Object* SetLocalDateValue(Handle<JSDate> date, double time_val) {
} else {
time_val = std::numeric_limits<double>::quiet_NaN();
}
return *JSDate::SetValue(date, TimeClip(time_val));
return *JSDate::SetValue(date, DateCache::TimeClip(time_val));
}
} // namespace
......@@ -354,7 +346,8 @@ BUILTIN(DateUTC) {
}
double const day = MakeDay(year, month, date);
double const time = MakeTime(hours, minutes, seconds, ms);
return *isolate->factory()->NewNumber(TimeClip(MakeDate(day, time)));
return *isolate->factory()->NewNumber(
DateCache::TimeClip(MakeDate(day, time)));
}
// ES6 section 20.3.4.20 Date.prototype.setDate ( date )
......@@ -558,7 +551,7 @@ BUILTIN(DatePrototypeSetTime) {
CHECK_RECEIVER(JSDate, date, "Date.prototype.setTime");
Handle<Object> value = args.atOrUndefined(isolate, 1);
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, value, Object::ToNumber(value));
return *JSDate::SetValue(date, TimeClip(value->Number()));
return *JSDate::SetValue(date, DateCache::TimeClip(value->Number()));
}
// ES6 section 20.3.4.28 Date.prototype.setUTCDate ( date )
......@@ -575,7 +568,7 @@ BUILTIN(DatePrototypeSetUTCDate) {
isolate->date_cache()->YearMonthDayFromDays(days, &year, &month, &day);
double const time_val =
MakeDate(MakeDay(year, month, value->Number()), time_within_day);
return *JSDate::SetValue(date, TimeClip(time_val));
return *JSDate::SetValue(date, DateCache::TimeClip(time_val));
}
// ES6 section 20.3.4.29 Date.prototype.setUTCFullYear (year, month, date)
......@@ -607,7 +600,7 @@ BUILTIN(DatePrototypeSetUTCFullYear) {
}
}
double const time_val = MakeDate(MakeDay(y, m, dt), time_within_day);
return *JSDate::SetValue(date, TimeClip(time_val));
return *JSDate::SetValue(date, DateCache::TimeClip(time_val));
}
// ES6 section 20.3.4.30 Date.prototype.setUTCHours(hour, min, sec, ms)
......@@ -643,7 +636,7 @@ BUILTIN(DatePrototypeSetUTCHours) {
}
time_val = MakeDate(day, MakeTime(h, m, s, milli));
}
return *JSDate::SetValue(date, TimeClip(time_val));
return *JSDate::SetValue(date, DateCache::TimeClip(time_val));
}
// ES6 section 20.3.4.31 Date.prototype.setUTCMilliseconds(ms)
......@@ -662,7 +655,7 @@ BUILTIN(DatePrototypeSetUTCMilliseconds) {
int s = (time_within_day / 1000) % 60;
time_val = MakeDate(day, MakeTime(h, m, s, ms->Number()));
}
return *JSDate::SetValue(date, TimeClip(time_val));
return *JSDate::SetValue(date, DateCache::TimeClip(time_val));
}
// ES6 section 20.3.4.32 Date.prototype.setUTCMinutes ( min, sec, ms )
......@@ -693,7 +686,7 @@ BUILTIN(DatePrototypeSetUTCMinutes) {
}
time_val = MakeDate(day, MakeTime(h, m, s, milli));
}
return *JSDate::SetValue(date, TimeClip(time_val));
return *JSDate::SetValue(date, DateCache::TimeClip(time_val));
}
// ES6 section 20.3.4.31 Date.prototype.setUTCMonth ( month, date )
......@@ -719,7 +712,7 @@ BUILTIN(DatePrototypeSetUTCMonth) {
}
time_val = MakeDate(MakeDay(year, m, dt), time_within_day);
}
return *JSDate::SetValue(date, TimeClip(time_val));
return *JSDate::SetValue(date, DateCache::TimeClip(time_val));
}
// ES6 section 20.3.4.34 Date.prototype.setUTCSeconds ( sec, ms )
......@@ -745,7 +738,7 @@ BUILTIN(DatePrototypeSetUTCSeconds) {
}
time_val = MakeDate(day, MakeTime(h, m, s, milli));
}
return *JSDate::SetValue(date, TimeClip(time_val));
return *JSDate::SetValue(date, DateCache::TimeClip(time_val));
}
// ES6 section 20.3.4.35 Date.prototype.toDateString ( )
......
......@@ -4,8 +4,9 @@
#include "src/date.h"
#include "src/objects.h"
#include "src/conversions.h"
#include "src/objects-inl.h"
#include "src/objects.h"
#ifdef V8_INTL_SUPPORT
#include "src/intl.h"
......@@ -65,6 +66,13 @@ void DateCache::ResetDateCache() {
dst_tz_name_ = nullptr;
}
// ECMA 262 - ES#sec-timeclip TimeClip (time)
double DateCache::TimeClip(double time) {
if (-kMaxTimeInMs <= time && time <= kMaxTimeInMs) {
return DoubleToInteger(time) + 0.0;
}
return std::numeric_limits<double>::quiet_NaN();
}
void DateCache::ClearSegment(DST* segment) {
segment->start_sec = kMaxEpochTimeInSec;
......
......@@ -62,6 +62,8 @@ class DateCache {
return static_cast<int>(time_ms - days * kMsPerDay);
}
// ECMA 262 - ES#sec-timeclip TimeClip (time)
static double TimeClip(double time);
// Given the number of days since the epoch, computes the weekday.
// ECMA 262 - 15.9.1.6.
......
......@@ -14,6 +14,7 @@
#include "src/api-natives.h"
#include "src/api.h"
#include "src/arguments.h"
#include "src/date.h"
#include "src/global-handles.h"
#include "src/heap/factory.h"
#include "src/intl.h"
......@@ -260,9 +261,8 @@ RUNTIME_FUNCTION(Runtime_InternalDateFormat) {
CONVERT_ARG_HANDLE_CHECKED(JSObject, date_format_holder, 0);
CONVERT_NUMBER_ARG_HANDLE_CHECKED(date, 1);
double date_value = date->Number();
// Check for +-Infinity and Nan
if (!std::isfinite(date_value)) {
double date_value = DateCache::TimeClip(date->Number());
if (std::isnan(date_value)) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewRangeError(MessageTemplate::kInvalidTimeValue));
}
......@@ -366,8 +366,8 @@ RUNTIME_FUNCTION(Runtime_InternalDateFormatToParts) {
CONVERT_ARG_HANDLE_CHECKED(JSObject, date_format_holder, 0);
CONVERT_NUMBER_ARG_HANDLE_CHECKED(date, 1);
double date_value = date->Number();
if (!std::isfinite(date_value)) {
double date_value = DateCache::TimeClip(date->Number());
if (std::isnan(date_value)) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewRangeError(MessageTemplate::kInvalidTimeValue));
}
......
......@@ -21,10 +21,12 @@ var locales = [
"th-u-ca-buddhist",
];
var hugeNum = 1.7976931348623157e+308;
// Used to test with 1.7976931348623157e+308, but it does not work
// any more with TimeClip. Instead, try the largest time value.
var end_of_time = 8.64e15;
locales.forEach(function(loc) {
var df = new Intl.DateTimeFormat(loc, {month: "long"});
assertFalse(df.format(hugeNum) == '');
assertFalse(df.format(end_of_time) == '');
}
);
......@@ -435,12 +435,6 @@
'language/expressions/call/eval-spread-empty-leading': [FAIL],
'language/expressions/call/eval-spread-empty-trailing': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=7471
'intl402/DateTimeFormat/prototype/format/time-clip-near-time-boundaries': [FAIL],
'intl402/DateTimeFormat/prototype/format/time-clip-to-integer': [FAIL],
'intl402/DateTimeFormat/prototype/formatToParts/time-clip-near-time-boundaries': [FAIL],
'intl402/DateTimeFormat/prototype/formatToParts/time-clip-to-integer': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=7472
'intl402/NumberFormat/currency-digits': [FAIL],
......
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