Commit 22b441ac authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Refactor CreateNumberFormat into Intl:: for later C++ usage.

Bug: v8:7960
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: I2ea86824e98d9c92a838b8c515e9ab238abe51d1
Reviewed-on: https://chromium-review.googlesource.com/1149616
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54709}
parent 6c27d79d
......@@ -1734,5 +1734,32 @@ Handle<Smi> Intl::CurrencyDigits(Isolate* isolate, Handle<String> currency) {
return Handle<Smi>(Smi::FromInt(fraction_digits), isolate);
}
MaybeHandle<JSObject> Intl::CreateNumberFormat(Isolate* isolate,
Handle<String> locale,
Handle<JSObject> options,
Handle<JSObject> resolved) {
Handle<JSFunction> constructor(
isolate->native_context()->intl_number_format_function(), isolate);
Handle<JSObject> local_object;
ASSIGN_RETURN_ON_EXCEPTION(isolate, local_object,
JSObject::New(constructor, constructor), JSObject);
// Set number formatter as embedder field of the resulting JS object.
icu::DecimalFormat* number_format =
NumberFormat::InitializeNumberFormat(isolate, locale, options, resolved);
CHECK_NOT_NULL(number_format);
local_object->SetEmbedderField(NumberFormat::kDecimalFormatIndex,
reinterpret_cast<Smi*>(number_format));
Handle<Object> wrapper = isolate->global_handles()->Create(*local_object);
GlobalHandles::MakeWeak(wrapper.location(), wrapper.location(),
NumberFormat::DeleteNumberFormat,
WeakCallbackType::kInternalFields);
return local_object;
}
} // namespace internal
} // namespace v8
......@@ -306,6 +306,10 @@ class Intl {
// ecma-402/#sec-currencydigits
// The currency is expected to an all upper case string value.
static Handle<Smi> CurrencyDigits(Isolate* isolate, Handle<String> currency);
V8_WARN_UNUSED_RESULT static MaybeHandle<JSObject> CreateNumberFormat(
Isolate* isolate, Handle<String> locale, Handle<JSObject> options,
Handle<JSObject> resolved);
};
} // namespace internal
......
......@@ -217,27 +217,8 @@ RUNTIME_FUNCTION(Runtime_CreateNumberFormat) {
CONVERT_ARG_HANDLE_CHECKED(String, locale, 0);
CONVERT_ARG_HANDLE_CHECKED(JSObject, options, 1);
CONVERT_ARG_HANDLE_CHECKED(JSObject, resolved, 2);
Handle<JSFunction> constructor(
isolate->native_context()->intl_number_format_function(), isolate);
Handle<JSObject> local_object;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, local_object,
JSObject::New(constructor, constructor));
// Set number formatter as embedder field of the resulting JS object.
icu::DecimalFormat* number_format =
NumberFormat::InitializeNumberFormat(isolate, locale, options, resolved);
CHECK_NOT_NULL(number_format);
local_object->SetEmbedderField(NumberFormat::kDecimalFormatIndex,
reinterpret_cast<Smi*>(number_format));
Handle<Object> wrapper = isolate->global_handles()->Create(*local_object);
GlobalHandles::MakeWeak(wrapper.location(), wrapper.location(),
NumberFormat::DeleteNumberFormat,
WeakCallbackType::kInternalFields);
return *local_object;
RETURN_RESULT_OR_FAILURE(
isolate, Intl::CreateNumberFormat(isolate, locale, options, resolved));
}
RUNTIME_FUNCTION(Runtime_InternalNumberFormat) {
......
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