Commit 30af54c4 authored by Ujjwal Sharma's avatar Ujjwal Sharma Committed by Commit Bot

[intl] Port numberformat#resolvedOptions to C++

Bug: v8:5751
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: I91a7305d82423d3a7b1d2fc44282b6116c4c746c
Reviewed-on: https://chromium-review.googlesource.com/1208652
Commit-Queue: Ujjwal Sharma <usharma1998@gmail.com>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55805}
parent 93fea343
......@@ -2960,6 +2960,10 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
factory->Object_string(),
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
SimpleInstallFunction(isolate_, prototype, "resolvedOptions",
Builtins::kNumberFormatPrototypeResolvedOptions, 0,
false);
SimpleInstallFunction(isolate_, prototype, "formatToParts",
Builtins::kNumberFormatPrototypeFormatToParts, 1,
false);
......
......@@ -1395,6 +1395,8 @@ namespace internal {
CPP(NumberFormatPrototypeFormatNumber) \
/* ecma402 #sec-intl.numberformat.prototype.formattoparts */ \
CPP(NumberFormatPrototypeFormatToParts) \
/* ecma402 #sec-intl.numberformat.prototype.resolvedoptions */ \
CPP(NumberFormatPrototypeResolvedOptions) \
/* ecma402 #sec-intl.numberformat.supportedlocalesof */ \
CPP(NumberFormatSupportedLocalesOf) \
/* ecma402 #sec-intl.pluralrules */ \
......
......@@ -338,6 +338,23 @@ BUILTIN(NumberFormatConstructor) {
"Intl.NumberFormat");
}
BUILTIN(NumberFormatPrototypeResolvedOptions) {
HandleScope scope(isolate);
const char* const method = "Intl.NumberFormat.prototype.resolvedOptions";
// 1. Let nf be the this value.
// 2. If Type(nf) is not Object, throw a TypeError exception.
CHECK_RECEIVER(JSReceiver, number_format_holder, method);
// 3. Let nf be ? UnwrapNumberFormat(nf)
Handle<JSNumberFormat> number_format;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, number_format,
JSNumberFormat::UnwrapNumberFormat(isolate, number_format_holder));
return *JSNumberFormat::ResolvedOptions(isolate, number_format);
}
BUILTIN(NumberFormatPrototypeFormatNumber) {
const char* const method = "get Intl.NumberFormat.prototype.format";
HandleScope scope(isolate);
......
......@@ -391,16 +391,6 @@ DEFINE_METHOD(
}
);
/**
* NumberFormat resolvedOptions method.
*/
DEFINE_METHOD(
GlobalIntlNumberFormat.prototype,
resolvedOptions() {
return %NumberFormatResolvedOptions(this);
}
);
/**
* DateTimeFormat resolvedOptions method.
*/
......
......@@ -131,33 +131,6 @@ RUNTIME_FUNCTION(Runtime_DateTimeFormatResolvedOptions) {
isolate, JSDateTimeFormat::ResolvedOptions(isolate, format_holder));
}
RUNTIME_FUNCTION(Runtime_NumberFormatResolvedOptions) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(Object, number_format_obj, 0);
// 2. If Type(nf) is not Object, throw a TypeError exception
if (!number_format_obj->IsJSReceiver()) {
Handle<String> method_str = isolate->factory()->NewStringFromStaticChars(
"Intl.NumberFormat.prototype.resolvedOptions");
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kIncompatibleMethodReceiver,
method_str, number_format_obj));
}
// 3. Let nf be ? UnwrapNumberFormat(nf).
Handle<JSReceiver> format_holder =
Handle<JSReceiver>::cast(number_format_obj);
Handle<JSNumberFormat> number_format;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, number_format,
JSNumberFormat::UnwrapNumberFormat(isolate, format_holder));
return *JSNumberFormat::ResolvedOptions(isolate, number_format);
}
RUNTIME_FUNCTION(Runtime_PluralRulesSelect) {
HandleScope scope(isolate);
......
......@@ -207,7 +207,6 @@ namespace internal {
F(FormatList, 2, 1) \
F(FormatListToParts, 2, 1) \
F(GetDefaultICULocale, 0, 1) \
F(NumberFormatResolvedOptions, 1, 1) \
F(PluralRulesSelect, 2, 1) \
F(StringToLowerCaseIntl, 1, 1) \
F(StringToUpperCaseIntl, 1, 1) // End of macro.
......
// Copyright 2015 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.
let nf = Object.create(Intl.NumberFormat.prototype);
nf = Intl.NumberFormat.call(nf);
const actual = Intl.NumberFormat.prototype.resolvedOptions.call(nf);
const expected = new Intl.NumberFormat().resolvedOptions();
Object.keys(expected).forEach(key => assertEquals(expected[key], actual[key]));
assertEquals(Object.keys(expected).length, Object.keys(actual).length);
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