Commit 8093b4f3 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

Reland "[Intl] move Date.prototype.toLocale{,Date,Time}String to C++"

This is a reland of 8e57cd51

Original change's description:
> [Intl] move Date.prototype.toLocale{,Date,Time}String to C++
> 
> Bug: v8:7961
> Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
> Change-Id: Ie75eb443fc0907a4e1e4cafd4f5c06c23794f5a9
> Reviewed-on: https://chromium-review.googlesource.com/1156123
> Commit-Queue: Frank Tang <ftang@chromium.org>
> Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#55239}

Bug: v8:7961
Change-Id: Ib7dd3b7b3d363b7b8cb2dcd89a5d591fab592c81
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Reviewed-on: https://chromium-review.googlesource.com/1185763Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55368}
parent 5876d8f5
......@@ -2317,6 +2317,14 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
SimpleInstallFunction(isolate_, prototype, "toJSON",
Builtins::kDatePrototypeToJson, 1, false);
#ifdef V8_INTL_SUPPORT
SimpleInstallFunction(isolate_, prototype, "toLocaleString",
Builtins::kDatePrototypeToLocaleString, 0, false);
SimpleInstallFunction(isolate_, prototype, "toLocaleDateString",
Builtins::kDatePrototypeToLocaleDateString, 0, false);
SimpleInstallFunction(isolate_, prototype, "toLocaleTimeString",
Builtins::kDatePrototypeToLocaleTimeString, 0, false);
#else
// Install Intl fallback functions.
SimpleInstallFunction(isolate_, prototype, "toLocaleString",
Builtins::kDatePrototypeToString, 0, false);
......@@ -2324,6 +2332,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Builtins::kDatePrototypeToDateString, 0, false);
SimpleInstallFunction(isolate_, prototype, "toLocaleTimeString",
Builtins::kDatePrototypeToTimeString, 0, false);
#endif // V8_INTL_SUPPORT
// Install the @@toPrimitive function.
Handle<JSFunction> to_primitive = InstallFunction(
......
......@@ -10,6 +10,9 @@
#include "src/counters.h"
#include "src/dateparser-inl.h"
#include "src/objects-inl.h"
#ifdef V8_INTL_SUPPORT
#include "src/objects/intl-objects.h"
#endif
namespace v8 {
namespace internal {
......@@ -835,6 +838,53 @@ BUILTIN(DatePrototypeToTimeString) {
isolate, isolate->factory()->NewStringFromUtf8(CStrVector(buffer)));
}
#ifdef V8_INTL_SUPPORT
// ecma402 #sup-date.prototype.tolocaledatestring
BUILTIN(DatePrototypeToLocaleDateString) {
HandleScope scope(isolate);
CHECK_RECEIVER(JSDate, date, "Date.prototype.toLocaleDateString");
RETURN_RESULT_OR_FAILURE(
isolate,
DateFormat::ToLocaleDateTime(isolate,
date, // date
args.atOrUndefined(isolate, 1), // locales
args.atOrUndefined(isolate, 2), // options
"date", // required
"date", // defaults
"dateformatdate")); // service
}
// ecma402 #sup-date.prototype.tolocalestring
BUILTIN(DatePrototypeToLocaleString) {
HandleScope scope(isolate);
CHECK_RECEIVER(JSDate, date, "Date.prototype.toLocaleString");
RETURN_RESULT_OR_FAILURE(
isolate,
DateFormat::ToLocaleDateTime(isolate,
date, // date
args.atOrUndefined(isolate, 1), // locales
args.atOrUndefined(isolate, 2), // options
"any", // required
"all", // defaults
"dateformatall")); // service
}
// ecma402 #sup-date.prototype.tolocaletimestring
BUILTIN(DatePrototypeToLocaleTimeString) {
HandleScope scope(isolate);
CHECK_RECEIVER(JSDate, date, "Date.prototype.toLocaleTimeString");
RETURN_RESULT_OR_FAILURE(
isolate,
DateFormat::ToLocaleDateTime(isolate,
date, // date
args.atOrUndefined(isolate, 1), // locales
args.atOrUndefined(isolate, 2), // options
"time", // required
"time", // defaults
"dateformattime")); // service
}
#endif // V8_INTL_SUPPORT
// ES6 section 20.3.4.43 Date.prototype.toUTCString ( )
BUILTIN(DatePrototypeToUTCString) {
HandleScope scope(isolate);
......
......@@ -1338,6 +1338,12 @@ namespace internal {
CPP(NumberFormatPrototypeFormatToParts) \
/* ecma402 #sec-intl.datetimeformat.prototype.formattoparts */ \
CPP(DateTimeFormatPrototypeFormatToParts) \
/* ecma402 #sup-date.prototype.tolocaledatestring */ \
CPP(DatePrototypeToLocaleDateString) \
/* ecma402 #sup-date.prototype.tolocalestring */ \
CPP(DatePrototypeToLocaleString) \
/* ecma402 #sup-date.prototype.tolocaletimestring */ \
CPP(DatePrototypeToLocaleTimeString) \
/* ecma402 #new proposal */ \
/* ecma402 #sec-intl-listformat-constructor */ \
CPP(ListFormatConstructor) \
......
......@@ -1510,51 +1510,4 @@ function cachedOrNewService(service, locales, options, defaults) {
"cached_or_new_service", cachedOrNewService
]);
/**
* Formats a Date object (this) using locale and options values.
* If locale or options are omitted, defaults are used - both date and time are
* present in the output.
*/
DEFINE_METHOD(
GlobalDate.prototype,
toLocaleString() {
var locales = arguments[0];
var options = arguments[1];
return %ToLocaleDateTime(
this, locales, options, 'any', 'all', 'dateformatall');
}
);
/**
* Formats a Date object (this) using locale and options values.
* If locale or options are omitted, defaults are used - only date is present
* in the output.
*/
DEFINE_METHOD(
GlobalDate.prototype,
toLocaleDateString() {
var locales = arguments[0];
var options = arguments[1];
return %ToLocaleDateTime(
this, locales, options, 'date', 'date', 'dateformatdate');
}
);
/**
* Formats a Date object (this) using locale and options values.
* If locale or options are omitted, defaults are used - only time is present
* in the output.
*/
DEFINE_METHOD(
GlobalDate.prototype,
toLocaleTimeString() {
var locales = arguments[0];
var options = arguments[1];
return %ToLocaleDateTime(
this, locales, options, 'time', 'time', 'dateformattime');
}
);
})
......@@ -569,6 +569,7 @@ MaybeHandle<JSObject> CachedOrNewService(Isolate* isolate,
JSArray);
return Handle<JSObject>::cast(result);
}
} // namespace
icu::Locale Intl::CreateICULocale(Isolate* isolate,
......
......@@ -231,12 +231,10 @@ RUNTIME_FUNCTION(Runtime_CreateDateTimeFormat) {
RUNTIME_FUNCTION(Runtime_FormatDate) {
HandleScope scope(isolate);
DCHECK_EQ(2, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSObject, date_format_holder, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, date, 1);
RETURN_RESULT_OR_FAILURE(
isolate, DateFormat::DateTimeFormat(isolate, date_format_holder, date));
}
......@@ -487,24 +485,6 @@ RUNTIME_FUNCTION(Runtime_BreakIteratorBreakType) {
}
}
RUNTIME_FUNCTION(Runtime_ToLocaleDateTime) {
HandleScope scope(isolate);
DCHECK_EQ(6, args.length());
CONVERT_ARG_HANDLE_CHECKED(Object, date, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, locales, 1);
CONVERT_ARG_HANDLE_CHECKED(Object, options, 2);
CONVERT_ARG_HANDLE_CHECKED(String, required, 3);
CONVERT_ARG_HANDLE_CHECKED(String, defaults, 4);
CONVERT_ARG_HANDLE_CHECKED(String, service, 5);
RETURN_RESULT_OR_FAILURE(
isolate, DateFormat::ToLocaleDateTime(
isolate, date, locales, options, required->ToCString().get(),
defaults->ToCString().get(), service->ToCString().get()));
}
RUNTIME_FUNCTION(Runtime_ToDateTimeOptions) {
HandleScope scope(isolate);
DCHECK_EQ(args.length(), 3);
......
......@@ -227,7 +227,6 @@ namespace internal {
F(PluralRulesResolvedOptions, 1, 1) \
F(PluralRulesSelect, 2, 1) \
F(ToDateTimeOptions, 3, 1) \
F(ToLocaleDateTime, 6, 1) \
F(StringToLowerCaseIntl, 1, 1) \
F(StringToUpperCaseIntl, 1, 1) \
F(SupportedLocalesOf, 3, 1) \
......
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