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) { ...@@ -620,33 +620,20 @@ void DateFormat::DeleteDateFormat(const v8::WeakCallbackInfo<void>& data) {
GlobalHandles::Destroy(reinterpret_cast<Object**>(data.GetParameter())); GlobalHandles::Destroy(reinterpret_cast<Object**>(data.GetParameter()));
} }
MaybeHandle<String> DateFormat::FormatDate(Isolate* isolate, // ecma402/#sec-formatdatetime
Handle<JSObject> date_format_holder, // FormatDateTime( dateTimeFormat, x )
Handle<Object> date) { MaybeHandle<String> DateFormat::FormatDateTime(
// 3. If date is not provided or is undefined, then Isolate* isolate, Handle<JSObject> date_time_format_holder, double x) {
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();
}
double date_value = DateCache::TimeClip(x); double date_value = DateCache::TimeClip(x);
if (std::isnan(date_value)) { if (std::isnan(date_value)) {
THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kInvalidTimeValue), THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kInvalidTimeValue),
String); String);
} }
CHECK(Intl::IsObjectOfType(isolate, date_format_holder, CHECK(Intl::IsObjectOfType(isolate, date_time_format_holder,
Intl::Type::kDateTimeFormat)); Intl::Type::kDateTimeFormat));
icu::SimpleDateFormat* date_format = icu::SimpleDateFormat* date_format =
DateFormat::UnpackDateFormat(date_format_holder); DateFormat::UnpackDateFormat(date_time_format_holder);
CHECK_NOT_NULL(date_format); CHECK_NOT_NULL(date_format);
icu::UnicodeString result; icu::UnicodeString result;
...@@ -656,6 +643,28 @@ MaybeHandle<String> DateFormat::FormatDate(Isolate* isolate, ...@@ -656,6 +643,28 @@ MaybeHandle<String> DateFormat::FormatDate(Isolate* isolate,
reinterpret_cast<const uint16_t*>(result.getBuffer()), result.length())); 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( icu::DecimalFormat* NumberFormat::InitializeNumberFormat(
Isolate* isolate, Handle<String> locale, Handle<JSObject> options, Isolate* isolate, Handle<String> locale, Handle<JSObject> options,
Handle<JSObject> resolved) { Handle<JSObject> resolved) {
......
...@@ -49,9 +49,15 @@ class DateFormat { ...@@ -49,9 +49,15 @@ class DateFormat {
// holds the pointer gets garbage collected. // holds the pointer gets garbage collected.
static void DeleteDateFormat(const v8::WeakCallbackInfo<void>& data); 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 // ecma402/#sec-datetime-format-functions
V8_WARN_UNUSED_RESULT static MaybeHandle<String> FormatDate( // DateTime Format Functions
Isolate* isolate, Handle<JSObject> date_format_holder, V8_WARN_UNUSED_RESULT static MaybeHandle<String> DateTimeFormat(
Isolate* isolate, Handle<JSObject> date_time_format_holder,
Handle<Object> date); Handle<Object> date);
// Layout description. // Layout description.
......
...@@ -237,7 +237,7 @@ RUNTIME_FUNCTION(Runtime_FormatDate) { ...@@ -237,7 +237,7 @@ RUNTIME_FUNCTION(Runtime_FormatDate) {
CONVERT_ARG_HANDLE_CHECKED(Object, date, 1); CONVERT_ARG_HANDLE_CHECKED(Object, date, 1);
RETURN_RESULT_OR_FAILURE( RETURN_RESULT_OR_FAILURE(
isolate, DateFormat::FormatDate(isolate, date_format_holder, date)); isolate, DateFormat::DateTimeFormat(isolate, date_format_holder, date));
} }
RUNTIME_FUNCTION(Runtime_CreateNumberFormat) { 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