Commit a1c69e8d authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Split FormatDate into two functions

Previously, FormatDate implemented two functions:
(a) "DateTime Format Functions" as in ecma402/#sec-datetime-format-functions
(b) "FormatDateTime( dateTimeFormat, x )" as in ecma402/#sec-formatdatetime

This patch split FormatDate into two separate functions exactly as they are specified.

Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: Iae47f4d992f1767968e5a6df7d1a45a95bc33192
Reviewed-on: https://chromium-review.googlesource.com/1178886
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55177}
parent cfbd826b
......@@ -620,33 +620,20 @@ void DateFormat::DeleteDateFormat(const v8::WeakCallbackInfo<void>& data) {
GlobalHandles::Destroy(reinterpret_cast<Object**>(data.GetParameter()));
}
MaybeHandle<String> DateFormat::FormatDate(Isolate* isolate,
Handle<JSObject> date_format_holder,
Handle<Object> date) {
// 3. If date is not provided or is undefined, then
double x;
if (date->IsUndefined()) {
// 3.a Let x be Call(%Date_now%, undefined).
x = JSDate::CurrentTimeValue(isolate);
} else {
// 4. Else,
// a. Let x be ? ToNumber(date).
ASSIGN_RETURN_ON_EXCEPTION(isolate, date, Object::ToNumber(isolate, date),
String);
CHECK(date->IsNumber());
x = date->Number();
}
// ecma402/#sec-formatdatetime
// FormatDateTime( dateTimeFormat, x )
MaybeHandle<String> DateFormat::FormatDateTime(
Isolate* isolate, Handle<JSObject> date_time_format_holder, double x) {
double date_value = DateCache::TimeClip(x);
if (std::isnan(date_value)) {
THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kInvalidTimeValue),
String);
}
CHECK(Intl::IsObjectOfType(isolate, date_format_holder,
CHECK(Intl::IsObjectOfType(isolate, date_time_format_holder,
Intl::Type::kDateTimeFormat));
icu::SimpleDateFormat* date_format =
DateFormat::UnpackDateFormat(date_format_holder);
DateFormat::UnpackDateFormat(date_time_format_holder);
CHECK_NOT_NULL(date_format);
icu::UnicodeString result;
......@@ -656,6 +643,28 @@ MaybeHandle<String> DateFormat::FormatDate(Isolate* isolate,
reinterpret_cast<const uint16_t*>(result.getBuffer()), result.length()));
}
// ecma402/#sec-datetime-format-functions
// DateTime Format Functions
MaybeHandle<String> DateFormat::DateTimeFormat(
Isolate* isolate, Handle<JSObject> date_time_format_holder,
Handle<Object> date) {
// 3. If date is not provided or is undefined, then
double x;
if (date->IsUndefined()) {
// 3.a Let x be Call(%Date_now%, undefined).
x = JSDate::CurrentTimeValue(isolate);
} else {
// 4. Else,
// a. Let x be ? ToNumber(date).
ASSIGN_RETURN_ON_EXCEPTION(isolate, date, Object::ToNumber(isolate, date),
String);
CHECK(date->IsNumber());
x = date->Number();
}
// 5. Return FormatDateTime(dtf, x).
return DateFormat::FormatDateTime(isolate, date_time_format_holder, x);
}
icu::DecimalFormat* NumberFormat::InitializeNumberFormat(
Isolate* isolate, Handle<String> locale, Handle<JSObject> options,
Handle<JSObject> resolved) {
......
......@@ -49,9 +49,15 @@ class DateFormat {
// holds the pointer gets garbage collected.
static void DeleteDateFormat(const v8::WeakCallbackInfo<void>& data);
// ecma402/#sec-formatdatetime
// FormatDateTime( dateTimeFormat, x )
V8_WARN_UNUSED_RESULT static MaybeHandle<String> FormatDateTime(
Isolate* isolate, Handle<JSObject> date_time_format_holder, double x);
// ecma402/#sec-datetime-format-functions
V8_WARN_UNUSED_RESULT static MaybeHandle<String> FormatDate(
Isolate* isolate, Handle<JSObject> date_format_holder,
// DateTime Format Functions
V8_WARN_UNUSED_RESULT static MaybeHandle<String> DateTimeFormat(
Isolate* isolate, Handle<JSObject> date_time_format_holder,
Handle<Object> date);
// Layout description.
......
......@@ -237,7 +237,7 @@ RUNTIME_FUNCTION(Runtime_FormatDate) {
CONVERT_ARG_HANDLE_CHECKED(Object, date, 1);
RETURN_RESULT_OR_FAILURE(
isolate, DateFormat::FormatDate(isolate, date_format_holder, date));
isolate, DateFormat::DateTimeFormat(isolate, date_format_holder, date));
}
RUNTIME_FUNCTION(Runtime_CreateNumberFormat) {
......
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