Commit 273c83db authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

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

The expectation is changed in https://chromium-review.googlesource.com/c/chromium/src/+/1196032

revert of https://chromium-review.googlesource.com/c/v8/v8/+/1188143
to reland https://chromium-review.googlesource.com/c/v8/v8/+/1185763

v8:7961

Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng;luci.chromium.try:linux_chromium_rel_ng;luci.v8.try:v8_linux_blink_rel
Change-Id: I461db83b377c31abda72f2ce9c4501fcdd3b2663
Reviewed-on: https://chromium-review.googlesource.com/1195539Reviewed-by: 's avatarJungshik Shin <jshin@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55537}
parent 88cffb82
......@@ -2321,6 +2321,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);
......@@ -2328,6 +2336,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);
......
......@@ -1343,6 +1343,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) \
......
......@@ -1161,51 +1161,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');
}
);
})
......@@ -512,6 +512,7 @@ MaybeHandle<JSObject> CachedOrNewService(Isolate* isolate,
JSArray);
return Handle<JSObject>::cast(result);
}
} // namespace
icu::Locale Intl::CreateICULocale(Isolate* isolate,
......
......@@ -400,24 +400,6 @@ RUNTIME_FUNCTION(Runtime_CreateBreakIterator) {
return *local_object;
}
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);
......
......@@ -222,7 +222,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) \
// End of macro.
......
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