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

[Intl] move DateTimeFormat.prototype.resolvedOptions to c++

Bug: v8:8066
Change-Id: I931de0472941fca8f68739a05fa38dee308d59f4
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng;luci.chromium.try:linux_chromium_rel_ng
Reviewed-on: https://chromium-review.googlesource.com/1212467Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56227}
parent 93cbb579
......@@ -2929,6 +2929,10 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
factory->Object_string(),
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
SimpleInstallFunction(isolate_, prototype, "resolvedOptions",
Builtins::kDateTimeFormatPrototypeResolvedOptions,
0, false);
SimpleInstallFunction(isolate_, prototype, "formatToParts",
Builtins::kDateTimeFormatPrototypeFormatToParts, 1,
false);
......
......@@ -1361,6 +1361,8 @@ namespace internal {
CPP(DateTimeFormatPrototypeFormat) \
/* ecma402 #sec-intl.datetimeformat.prototype.formattoparts */ \
CPP(DateTimeFormatPrototypeFormatToParts) \
/* ecma402 #sec-intl.datetimeformat.prototype.resolvedoptions */ \
CPP(DateTimeFormatPrototypeResolvedOptions) \
/* ecma402 #sec-intl.datetimeformat.supportedlocalesof */ \
CPP(DateTimeFormatSupportedLocalesOf) \
/* ecma402 #sec-intl-listformat-constructor */ \
......
......@@ -186,6 +186,21 @@ BUILTIN(NumberFormatPrototypeFormatToParts) {
isolate, number_format, x->Number()));
}
BUILTIN(DateTimeFormatPrototypeResolvedOptions) {
const char* const method = "Intl.DateTimeFormat.prototype.resolvedOptions";
HandleScope scope(isolate);
CHECK_RECEIVER(JSReceiver, format_holder, method);
// 3. Let dtf be ? UnwrapDateTimeFormat(dtf).
Handle<JSDateTimeFormat> date_time_format;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, date_time_format,
JSDateTimeFormat::UnwrapDateTimeFormat(isolate, format_holder));
RETURN_RESULT_OR_FAILURE(
isolate, JSDateTimeFormat::ResolvedOptions(isolate, date_time_format));
}
BUILTIN(DateTimeFormatSupportedLocalesOf) {
HandleScope scope(isolate);
RETURN_RESULT_OR_FAILURE(
......
......@@ -384,16 +384,6 @@ DEFINE_METHOD(
}
);
/**
* DateTimeFormat resolvedOptions method.
*/
DEFINE_METHOD(
GlobalIntlDateTimeFormat.prototype,
resolvedOptions() {
return %DateTimeFormatResolvedOptions(this);
}
);
// Save references to Intl objects and methods we use, for added security.
var savedObjects = {
__proto__: null,
......
......@@ -293,14 +293,8 @@ std::string JSDateTimeFormat::CanonicalizeTimeZoneID(Isolate* isolate,
}
MaybeHandle<JSObject> JSDateTimeFormat::ResolvedOptions(
Isolate* isolate, Handle<JSReceiver> format_holder) {
Isolate* isolate, Handle<JSDateTimeFormat> date_time_format) {
Factory* factory = isolate->factory();
// 3. Let dtf be ? UnwrapDateTimeFormat(dtf).
Handle<JSDateTimeFormat> format;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, format,
JSDateTimeFormat::UnwrapDateTimeFormat(isolate, format_holder), JSObject);
// 4. Let options be ! ObjectCreate(%ObjectPrototype%).
Handle<JSObject> options = factory->NewJSObject(isolate->object_function());
......@@ -309,12 +303,13 @@ MaybeHandle<JSObject> JSDateTimeFormat::ResolvedOptions(
Handle<Object> resolved_obj;
// locale
Handle<String> locale(format->locale(), isolate);
Handle<String> locale(date_time_format->locale(), isolate);
CHECK(JSReceiver::CreateDataProperty(
isolate, options, factory->locale_string(), locale, kDontThrow)
.FromJust());
icu::SimpleDateFormat* icu_simple_date_format = UnpackDateFormat(format);
icu::SimpleDateFormat* icu_simple_date_format =
UnpackDateFormat(date_time_format);
// calendar
const icu::Calendar* calendar = icu_simple_date_format->getCalendar();
// getType() returns legacy calendar type name instead of LDML/BCP47 calendar
......@@ -338,8 +333,9 @@ MaybeHandle<JSObject> JSDateTimeFormat::ResolvedOptions(
.FromJust());
// numberingSystem
if (format->numbering_system()->IsString()) {
Handle<String> numbering_system(format->numbering_system(), isolate);
if (date_time_format->numbering_system()->IsString()) {
Handle<String> numbering_system(date_time_format->numbering_system(),
isolate);
CHECK(JSReceiver::CreateDataProperty(isolate, options,
factory->numberingSystem_string(),
numbering_system, kDontThrow)
......@@ -386,7 +382,6 @@ MaybeHandle<JSObject> JSDateTimeFormat::ResolvedOptions(
std::string pattern;
pattern_unicode.toUTF8String(pattern);
SetPropertyFromPattern(isolate, pattern, options);
return options;
}
......
......@@ -32,7 +32,7 @@ class JSDateTimeFormat : public JSObject {
Handle<JSDateTimeFormat> date_time_format);
V8_WARN_UNUSED_RESULT static MaybeHandle<JSObject> ResolvedOptions(
Isolate* isolate, Handle<JSReceiver> format_holder);
Isolate* isolate, Handle<JSDateTimeFormat> date_time_format);
// ecma402/#sec-unwrapdatetimeformat
V8_WARN_UNUSED_RESULT static MaybeHandle<JSDateTimeFormat>
......
......@@ -110,27 +110,6 @@ RUNTIME_FUNCTION(Runtime_GetDefaultICULocale) {
Intl::DefaultLocale(isolate).c_str());
}
// ecma402/#sec-intl.datetimeformat.prototype.resolvedoptions
RUNTIME_FUNCTION(Runtime_DateTimeFormatResolvedOptions) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
// 1. Let dtf be this value.
CONVERT_ARG_HANDLE_CHECKED(Object, dtf, 0);
// 2. If Type(dtf) is not Object, throw a TypeError exception.
if (!dtf->IsJSReceiver()) {
Handle<String> method_str = isolate->factory()->NewStringFromStaticChars(
"Intl.DateTimeFormat.prototype.resolvedOptions");
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kIncompatibleMethodReceiver,
method_str, dtf));
}
Handle<JSReceiver> format_holder = Handle<JSReceiver>::cast(dtf);
RETURN_RESULT_OR_FAILURE(
isolate, JSDateTimeFormat::ResolvedOptions(isolate, format_holder));
}
RUNTIME_FUNCTION(Runtime_StringToLowerCaseIntl) {
HandleScope scope(isolate);
DCHECK_EQ(args.length(), 1);
......
......@@ -192,7 +192,6 @@ namespace internal {
F(AvailableLocalesOf, 1, 1) \
F(CanonicalizeLanguageTag, 1, 1) \
F(DateCacheVersion, 0, 1) \
F(DateTimeFormatResolvedOptions, 1, 1) \
F(FormatList, 2, 1) \
F(FormatListToParts, 2, 1) \
F(GetDefaultICULocale, 0, 1) \
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Test the Intl.DateTimeFormat.prototype.resolvedOptions will properly handle
// 3. Let dtf be ? UnwrapDateTimeFormat(dtf).
var x = Object.create(Intl.DateTimeFormat.prototype);
x = Intl.DateTimeFormat.call(x, 'en');
var resolvedOptions = Intl.DateTimeFormat.prototype.resolvedOptions.call(x);
assertEquals(resolvedOptions.locale, 'en')
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