[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}
This commit is contained in:
Frank Tang 2018-08-20 14:34:21 -07:00 committed by Commit Bot
parent 97473f49e5
commit 8e57cd51fd
7 changed files with 66 additions and 68 deletions

View File

@ -2315,6 +2315,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);
@ -2322,6 +2330,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(

View File

@ -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);

View File

@ -1333,6 +1333,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) \

View File

@ -1503,51 +1503,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');
}
);
})

View File

@ -569,6 +569,7 @@ MaybeHandle<JSObject> CachedOrNewService(Isolate* isolate,
JSArray);
return Handle<JSObject>::cast(result);
}
} // namespace
icu::Locale Intl::CreateICULocale(Isolate* isolate,

View File

@ -230,12 +230,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));
}
@ -486,24 +484,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);

View File

@ -230,7 +230,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) \