Commit 7aced299 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Cache intl objects in isolate

Remove old code in v8::Date::DateTimeConfigurationChangeNotification
Add code to clear date time cache object in isolate.

Running benchmark
python -u tools/run_perf.py --binary-override-path \
  out/x64.release/d8 --filter "JSTests/Strings/StringLocaleCompare" \
  test/js-perf-test/JSTests.json
python -u tools/run_perf.py --binary-override-path \
  out/x64.release/d8 --filter "JSTests/Dates" \
  test/js-perf-test/JSTests.json
python -u tools/run_perf.py --binary-override-path \
  out/x64.release/d8 --filter "JSTests/Numbers" \
  test/js-perf-test/JSTests.json

BEFORE THE FIX:
StringLocaleCompare-Strings(Score): 184287
toLocaleDateString-Dates(Score): 10456
toLocaleString-Dates(Score): 10436
toLocaleTimeString-Dates(Score): 10700
toLocaleString-Numbers(Score): 2935

AFTER THE FIX in Patch Set 13:
StringLocaleCompare-Strings(Score): 57470000
toLocaleDateString-Dates(Score): 6141000
toLocaleString-Dates(Score): 4093000
toLocaleTimeString-Dates(Score): 6323000
toLocaleString-Numbers(Score): 3371000

Bug: chromium:901748, chromium:901747, v8:5751
Change-Id: I7578e2ced0fe967dce6424d17f15ab806cc522be
Reviewed-on: https://chromium-review.googlesource.com/c/1320892
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57484}
parent 205860b1
......@@ -6832,6 +6832,14 @@ void v8::Date::DateTimeConfigurationChangeNotification(Isolate* isolate) {
LOG_API(i_isolate, Date, DateTimeConfigurationChangeNotification);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
i_isolate->date_cache()->ResetDateCache();
#ifdef V8_INTL_SUPPORT
i_isolate->clear_cached_icu_object(
i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormat);
i_isolate->clear_cached_icu_object(
i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormatForTime);
i_isolate->clear_cached_icu_object(
i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormatForDate);
#endif // V8_INTL_SUPPORT
}
......
......@@ -851,12 +851,11 @@ BUILTIN(DatePrototypeToLocaleDateString) {
RETURN_RESULT_OR_FAILURE(
isolate, JSDateTimeFormat::ToLocaleDateTime(
isolate,
date, // date
args.atOrUndefined(isolate, 1), // locales
args.atOrUndefined(isolate, 2), // options
JSDateTimeFormat::RequiredOption::kDate, // required
JSDateTimeFormat::DefaultsOption::kDate, // defaults
Intl::CacheType::kDateTimeFormatForDateToLocaleDateString));
date, // date
args.atOrUndefined(isolate, 1), // locales
args.atOrUndefined(isolate, 2), // options
JSDateTimeFormat::RequiredOption::kDate, // required
JSDateTimeFormat::DefaultsOption::kDate)); // defaults
}
// ecma402 #sup-date.prototype.tolocalestring
......@@ -870,12 +869,11 @@ BUILTIN(DatePrototypeToLocaleString) {
RETURN_RESULT_OR_FAILURE(
isolate, JSDateTimeFormat::ToLocaleDateTime(
isolate,
date, // date
args.atOrUndefined(isolate, 1), // locales
args.atOrUndefined(isolate, 2), // options
JSDateTimeFormat::RequiredOption::kAny, // required
JSDateTimeFormat::DefaultsOption::kAll, // defaults
Intl::CacheType::kDateTimeFormatForDateToLocaleString));
date, // date
args.atOrUndefined(isolate, 1), // locales
args.atOrUndefined(isolate, 2), // options
JSDateTimeFormat::RequiredOption::kAny, // required
JSDateTimeFormat::DefaultsOption::kAll)); // defaults
}
// ecma402 #sup-date.prototype.tolocaletimestring
......@@ -889,12 +887,11 @@ BUILTIN(DatePrototypeToLocaleTimeString) {
RETURN_RESULT_OR_FAILURE(
isolate, JSDateTimeFormat::ToLocaleDateTime(
isolate,
date, // date
args.atOrUndefined(isolate, 1), // locales
args.atOrUndefined(isolate, 2), // options
JSDateTimeFormat::RequiredOption::kTime, // required
JSDateTimeFormat::DefaultsOption::kTime, // defaults
Intl::CacheType::kDateTimeFormatForDateToLocaleTimeString));
date, // date
args.atOrUndefined(isolate, 1), // locales
args.atOrUndefined(isolate, 2), // options
JSDateTimeFormat::RequiredOption::kTime, // required
JSDateTimeFormat::DefaultsOption::kTime)); // defaults
}
#endif // V8_INTL_SUPPORT
......
......@@ -412,9 +412,13 @@ BUILTIN(NumberFormatInternalFormatNumber) {
}
double number = number_obj->Number();
icu::NumberFormat* icu_number_format =
number_format->icu_number_format()->raw();
CHECK_NOT_NULL(icu_number_format);
// Return FormatNumber(nf, x).
RETURN_RESULT_OR_FAILURE(
isolate, JSNumberFormat::FormatNumber(isolate, number_format, number));
RETURN_RESULT_OR_FAILURE(isolate, JSNumberFormat::FormatNumber(
isolate, *icu_number_format, number));
}
BUILTIN(DateTimeFormatConstructor) {
......@@ -886,7 +890,7 @@ BUILTIN(CollatorInternalCompare) {
// 1. Let collator be F.[[Collator]].
// 2. Assert: Type(collator) is Object and collator has an
// [[InitializedCollator]] internal slot.
Handle<JSCollator> collator_holder = Handle<JSCollator>(
Handle<JSCollator> collator = Handle<JSCollator>(
JSCollator::cast(context->get(
static_cast<int>(Intl::BoundFunctionContextSlot::kBoundFunction))),
isolate);
......@@ -906,7 +910,9 @@ BUILTIN(CollatorInternalCompare) {
Object::ToString(isolate, y));
// 7. Return CompareStrings(collator, X, Y).
return *Intl::CompareStrings(isolate, collator_holder, string_x, string_y);
icu::Collator* icu_collator = collator->icu_collator()->raw();
CHECK_NOT_NULL(icu_collator);
return *Intl::CompareStrings(isolate, *icu_collator, string_x, string_y);
}
// ecma402 #sec-segment-iterator-prototype-breakType
......
......@@ -8,6 +8,7 @@
#include <atomic>
#include <fstream> // NOLINT(readability/streams)
#include <memory>
#include <sstream>
#include <unordered_map>
......@@ -69,6 +70,9 @@
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-objects.h"
#include "src/zone/accounting-allocator.h"
#ifdef V8_INTL_SUPPORT
#include "unicode/uobject.h"
#endif // V8_INTL_SUPPORT
namespace v8 {
namespace internal {
......@@ -4330,6 +4334,21 @@ void Isolate::SetIdle(bool is_idle) {
}
}
#ifdef V8_INTL_SUPPORT
icu::UObject* Isolate::get_cached_icu_object(ICUObjectCacheType cache_type) {
return icu_object_cache_[cache_type].get();
}
void Isolate::set_icu_object_in_cache(ICUObjectCacheType cache_type,
std::shared_ptr<icu::UObject> obj) {
icu_object_cache_[cache_type] = obj;
}
void Isolate::clear_cached_icu_object(ICUObjectCacheType cache_type) {
icu_object_cache_.erase(cache_type);
}
#endif // V8_INTL_SUPPORT
bool StackLimitCheck::JsHasOverflowed(uintptr_t gap) const {
StackGuard* stack_guard = isolate_->stack_guard();
#ifdef USE_SIMULATOR
......
......@@ -6,6 +6,7 @@
#define V8_ISOLATE_H_
#include <cstddef>
#include <functional>
#include <memory>
#include <queue>
#include <unordered_map>
......@@ -36,6 +37,13 @@
#include "src/thread-id.h"
#include "src/unicode.h"
#ifdef V8_INTL_SUPPORT
#include "unicode/uversion.h" // Define U_ICU_NAMESPACE.
namespace U_ICU_NAMESPACE {
class UObject;
} // namespace U_ICU_NAMESPACE
#endif // V8_INTL_SUPPORT
namespace v8 {
namespace base {
......@@ -1189,6 +1197,16 @@ class Isolate final : private HiddenFactory {
default_locale_ = locale;
}
// enum to access the icu object cache.
enum class ICUObjectCacheType{
kDefaultCollator, kDefaultNumberFormat, kDefaultSimpleDateFormat,
kDefaultSimpleDateFormatForTime, kDefaultSimpleDateFormatForDate};
icu::UObject* get_cached_icu_object(ICUObjectCacheType cache_type);
void set_icu_object_in_cache(ICUObjectCacheType cache_type,
std::shared_ptr<icu::UObject> obj);
void clear_cached_icu_object(ICUObjectCacheType cache_type);
#endif // V8_INTL_SUPPORT
static const int kProtectorValid = 1;
......@@ -1732,6 +1750,16 @@ class Isolate final : private HiddenFactory {
#ifdef V8_INTL_SUPPORT
std::string default_locale_;
struct ICUObjectCacheTypeHash {
std::size_t operator()(ICUObjectCacheType a) const {
return static_cast<std::size_t>(a);
}
};
std::unordered_map<ICUObjectCacheType, std::shared_ptr<icu::UObject>,
ICUObjectCacheTypeHash>
icu_object_cache_;
#endif // V8_INTL_SUPPORT
// Whether the isolate has been created for snapshotting.
......
......@@ -173,6 +173,16 @@ const UChar* GetUCharBufferFromFlat(const String::FlatContent& flat,
}
}
template <typename T>
MaybeHandle<T> New(Isolate* isolate, Handle<JSFunction> constructor,
Handle<Object> locales, Handle<Object> options) {
Handle<JSObject> result;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, result,
JSObject::New(constructor, constructor, Handle<AllocationSite>::null()),
T);
return T::Initialize(isolate, Handle<T>::cast(result), locales, options);
}
} // namespace
const uint8_t* Intl::ToLatin1LowerTable() { return &kToLower[0]; }
......@@ -909,25 +919,48 @@ MaybeHandle<Object> Intl::StringLocaleCompare(Isolate* isolate,
Handle<String> string2,
Handle<Object> locales,
Handle<Object> options) {
Handle<JSObject> collator;
// We only cache the instance when both locales and options are undefined,
// as that is the only case when the specified side-effects of examining
// those arguments are unobservable.
bool can_cache =
locales->IsUndefined(isolate) && options->IsUndefined(isolate);
if (can_cache) {
// Both locales and options are undefined, check the cache.
icu::Collator* cached_icu_collator =
static_cast<icu::Collator*>(isolate->get_cached_icu_object(
Isolate::ICUObjectCacheType::kDefaultCollator));
// We may use the cached icu::Collator for a fast path.
if (cached_icu_collator != nullptr) {
return Intl::CompareStrings(isolate, *cached_icu_collator, string1,
string2);
}
}
Handle<JSFunction> constructor = Handle<JSFunction>(
JSFunction::cast(
isolate->context()->native_context()->intl_collator_function()),
isolate);
Handle<JSCollator> collator;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, collator,
CachedOrNew(isolate, Intl::CacheType::kCollatorForStringLocaleCompare,
locales, options),
Object);
CHECK(collator->IsJSCollator());
return Intl::CompareStrings(isolate, Handle<JSCollator>::cast(collator),
New<JSCollator>(isolate, constructor, locales, options), Object);
if (can_cache) {
isolate->set_icu_object_in_cache(
Isolate::ICUObjectCacheType::kDefaultCollator,
std::static_pointer_cast<icu::UObject>(
collator->icu_collator()->get()));
}
return Intl::CompareStrings(isolate, *(collator->icu_collator()->raw()),
string1, string2);
}
// ecma402/#sec-collator-comparestrings
Handle<Object> Intl::CompareStrings(Isolate* isolate,
Handle<JSCollator> collator,
const icu::Collator& icu_collator,
Handle<String> string1,
Handle<String> string2) {
Factory* factory = isolate->factory();
icu::Collator* icu_collator = collator->icu_collator()->raw();
CHECK_NOT_NULL(icu_collator);
string1 = String::Flatten(isolate, string1);
string2 = String::Flatten(isolate, string2);
......@@ -936,7 +969,7 @@ Handle<Object> Intl::CompareStrings(Isolate* isolate,
UErrorCode status = U_ZERO_ERROR;
icu::UnicodeString string_val1 = Intl::ToICUUnicodeString(isolate, string1);
icu::UnicodeString string_val2 = Intl::ToICUUnicodeString(isolate, string2);
result = icu_collator->compare(string_val1, string_val2, status);
result = icu_collator.compare(string_val1, string_val2, status);
DCHECK(U_SUCCESS(status));
return factory->NewNumberFromInt(result);
......@@ -947,18 +980,6 @@ MaybeHandle<String> Intl::NumberToLocaleString(Isolate* isolate,
Handle<Object> num,
Handle<Object> locales,
Handle<Object> options) {
Handle<JSObject> number_format_holder;
// 2. Let numberFormat be ? Construct(%NumberFormat%, « locales, options »).
ASSIGN_RETURN_ON_EXCEPTION(
isolate, number_format_holder,
CachedOrNew(isolate,
Intl::CacheType::kNumberFormatForNumberToLocaleString,
locales, options),
String);
DCHECK(number_format_holder->IsJSNumberFormat());
Handle<JSNumberFormat> number_format = Handle<JSNumberFormat>(
JSNumberFormat::cast(*number_format_holder), isolate);
Handle<Object> number_obj;
ASSIGN_RETURN_ON_EXCEPTION(isolate, number_obj,
Object::ToNumber(isolate, num), String);
......@@ -966,8 +987,42 @@ MaybeHandle<String> Intl::NumberToLocaleString(Isolate* isolate,
// Spec treats -0 and +0 as 0.
double number = number_obj->Number() + 0;
// We only cache the instance when both locales and options are undefined,
// as that is the only case when the specified side-effects of examining
// those arguments are unobservable.
bool can_cache =
locales->IsUndefined(isolate) && options->IsUndefined(isolate);
if (can_cache) {
icu::NumberFormat* cached_number_format =
static_cast<icu::NumberFormat*>(isolate->get_cached_icu_object(
Isolate::ICUObjectCacheType::kDefaultNumberFormat));
// We may use the cached icu::NumberFormat for a fast path.
if (cached_number_format != nullptr) {
return JSNumberFormat::FormatNumber(isolate, *cached_number_format,
number);
}
}
Handle<JSFunction> constructor = Handle<JSFunction>(
JSFunction::cast(
isolate->context()->native_context()->intl_number_format_function()),
isolate);
Handle<JSNumberFormat> number_format;
// 2. Let numberFormat be ? Construct(%NumberFormat%, « locales, options »).
ASSIGN_RETURN_ON_EXCEPTION(
isolate, number_format,
New<JSNumberFormat>(isolate, constructor, locales, options), String);
if (can_cache) {
isolate->set_icu_object_in_cache(
Isolate::ICUObjectCacheType::kDefaultNumberFormat,
std::static_pointer_cast<icu::UObject>(
number_format->icu_number_format()->get()));
}
// Return FormatNumber(numberFormat, x).
return JSNumberFormat::FormatNumber(isolate, number_format, number);
return JSNumberFormat::FormatNumber(
isolate, *(number_format->icu_number_format()->raw()), number);
}
namespace {
......@@ -1743,46 +1798,5 @@ Maybe<Intl::MatcherOption> Intl::GetLocaleMatcher(Isolate* isolate,
{Intl::MatcherOption::kLookup, Intl::MatcherOption::kBestFit},
Intl::MatcherOption::kLookup);
}
template <typename T>
MaybeHandle<JSObject> New(Isolate* isolate, Object* constructor_obj,
Handle<Object> locales, Handle<Object> options) {
Handle<JSFunction> constructor =
Handle<JSFunction>(JSFunction::cast(constructor_obj), isolate);
Handle<JSObject> result;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, result,
JSObject::New(constructor, constructor, Handle<AllocationSite>::null()),
JSObject);
return T::Initialize(isolate, Handle<T>::cast(result), locales, options);
}
MaybeHandle<JSObject> Intl::CachedOrNew(Isolate* isolate,
Intl::CacheType cache_type,
Handle<Object> locales,
Handle<Object> options) {
// TODO(ftang): we may add cache mechanism here if both locales and locales
// are undefined.
Handle<Context> native_context =
Handle<Context>(isolate->context()->native_context(), isolate);
switch (cache_type) {
case Intl::CacheType::kCollatorForStringLocaleCompare:
return New<JSCollator>(isolate, native_context->intl_collator_function(),
locales, options);
case Intl::CacheType::kNumberFormatForNumberToLocaleString:
return New<JSNumberFormat>(isolate,
native_context->intl_number_format_function(),
locales, options);
case Intl::CacheType::kDateTimeFormatForDateToLocaleString:
case Intl::CacheType::kDateTimeFormatForDateToLocaleDateString:
case Intl::CacheType::kDateTimeFormatForDateToLocaleTimeString:
return New<JSDateTimeFormat>(
isolate, native_context->intl_date_time_format_function(), locales,
options);
}
}
} // namespace internal
} // namespace v8
......@@ -24,6 +24,7 @@
namespace U_ICU_NAMESPACE {
class BreakIterator;
class Collator;
class DecimalFormat;
class SimpleDateFormat;
class UnicodeString;
......@@ -158,7 +159,7 @@ class Intl {
Handle<Object> locales, Handle<Object> options);
V8_WARN_UNUSED_RESULT static Handle<Object> CompareStrings(
Isolate* isolate, Handle<JSCollator> collator, Handle<String> s1,
Isolate* isolate, const icu::Collator& collator, Handle<String> s1,
Handle<String> s2);
// ecma402/#sup-properties-of-the-number-prototype-object
......@@ -212,11 +213,6 @@ class Intl {
Isolate* isolate, Handle<JSReceiver> receiver,
Handle<JSFunction> constructor, bool has_initialized_slot);
// A factory method to got cached objects.
V8_WARN_UNUSED_RESULT static MaybeHandle<JSObject> CachedOrNewService(
Isolate* isolate, Handle<String> service, Handle<Object> locales,
Handle<Object> options, Handle<Object> internal_options);
// enum for "caseFirst" option: shared by Intl.Locale and Intl.Collator.
enum class CaseFirst { kUpper, kLower, kFalse, kUndefined };
......@@ -266,20 +262,6 @@ class Intl {
static const uint8_t* ToLatin1LowerTable();
static String* ConvertOneByteToLower(String* src, String* dst);
enum class CacheType {
kCollatorForStringLocaleCompare,
kDateTimeFormatForDateToLocaleString,
kDateTimeFormatForDateToLocaleDateString,
kDateTimeFormatForDateToLocaleTimeString,
kNumberFormatForNumberToLocaleString
};
// Factory method to create DateTimeFormat, NumberFormat and Collator
// for Date.prototype.toLocale(String|DateString|TimeString),
// Number.toLocaleString, and String.prototype.localeCompare.
V8_WARN_UNUSED_RESULT static MaybeHandle<JSObject> CachedOrNew(
Isolate* isolate, Intl::CacheType cache_type, Handle<Object> locales,
Handle<Object> options);
};
} // namespace internal
......
......@@ -429,7 +429,7 @@ namespace {
// ecma402/#sec-formatdatetime
// FormatDateTime( dateTimeFormat, x )
MaybeHandle<String> FormatDateTime(Isolate* isolate,
Handle<JSDateTimeFormat> date_time_format,
const icu::SimpleDateFormat& date_format,
double x) {
double date_value = DateCache::TimeClip(x);
if (std::isnan(date_value)) {
......@@ -437,12 +437,8 @@ MaybeHandle<String> FormatDateTime(Isolate* isolate,
String);
}
icu::SimpleDateFormat* date_format =
date_time_format->icu_simple_date_format()->raw();
CHECK_NOT_NULL(date_format);
icu::UnicodeString result;
date_format->format(date_value, result);
date_format.format(date_value, result);
return Intl::ToString(isolate, result);
}
......@@ -471,13 +467,29 @@ MaybeHandle<String> JSDateTimeFormat::DateTimeFormat(
x = date->Number();
}
// 5. Return FormatDateTime(dtf, x).
return FormatDateTime(isolate, date_time_format, x);
return FormatDateTime(
isolate, *(date_time_format->icu_simple_date_format()->raw()), x);
}
namespace {
Isolate::ICUObjectCacheType ConvertToCacheType(
JSDateTimeFormat::DefaultsOption type) {
switch (type) {
case JSDateTimeFormat::DefaultsOption::kDate:
return Isolate::ICUObjectCacheType::kDefaultSimpleDateFormatForDate;
case JSDateTimeFormat::DefaultsOption::kTime:
return Isolate::ICUObjectCacheType::kDefaultSimpleDateFormatForTime;
case JSDateTimeFormat::DefaultsOption::kAll:
return Isolate::ICUObjectCacheType::kDefaultSimpleDateFormat;
}
}
} // namespace
MaybeHandle<String> JSDateTimeFormat::ToLocaleDateTime(
Isolate* isolate, Handle<Object> date, Handle<Object> locales,
Handle<Object> options, RequiredOption required, DefaultsOption defaults,
Intl::CacheType cache_type) {
Handle<Object> options, RequiredOption required, DefaultsOption defaults) {
Isolate::ICUObjectCacheType cache_type = ConvertToCacheType(defaults);
Factory* factory = isolate->factory();
// 1. Let x be ? thisTimeValue(this value);
if (!date->IsJSDate()) {
......@@ -493,6 +505,20 @@ MaybeHandle<String> JSDateTimeFormat::ToLocaleDateTime(
return factory->Invalid_Date_string();
}
// We only cache the instance when both locales and options are undefined,
// as that is the only case when the specified side-effects of examining
// those arguments are unobservable.
bool can_cache =
locales->IsUndefined(isolate) && options->IsUndefined(isolate);
if (can_cache) {
// Both locales and options are undefined, check the cache.
icu::SimpleDateFormat* cached_icu_simple_date_format =
static_cast<icu::SimpleDateFormat*>(
isolate->get_cached_icu_object(cache_type));
if (cached_icu_simple_date_format != nullptr) {
return FormatDateTime(isolate, *cached_icu_simple_date_format, x);
}
}
// 3. Let options be ? ToDateTimeOptions(options, required, defaults).
Handle<JSObject> internal_options;
ASSIGN_RETURN_ON_EXCEPTION(
......@@ -500,17 +526,31 @@ MaybeHandle<String> JSDateTimeFormat::ToLocaleDateTime(
ToDateTimeOptions(isolate, options, required, defaults), String);
// 4. Let dateFormat be ? Construct(%DateTimeFormat%, « locales, options »).
Handle<JSObject> object;
Handle<JSFunction> constructor = Handle<JSFunction>(
JSFunction::cast(isolate->context()
->native_context()
->intl_date_time_format_function()),
isolate);
Handle<JSObject> obj;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, object,
Intl::CachedOrNew(isolate, cache_type, locales, internal_options),
isolate, obj,
JSObject::New(constructor, constructor, Handle<AllocationSite>::null()),
String);
Handle<JSDateTimeFormat> date_time_format;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, date_time_format,
JSDateTimeFormat::Initialize(isolate, Handle<JSDateTimeFormat>::cast(obj),
locales, internal_options),
String);
CHECK(object->IsJSDateTimeFormat());
Handle<JSDateTimeFormat> date_time_format =
Handle<JSDateTimeFormat>::cast(object);
if (can_cache) {
isolate->set_icu_object_in_cache(
cache_type, std::static_pointer_cast<icu::UObject>(
date_time_format->icu_simple_date_format()->get()));
}
// 5. Return FormatDateTime(dateFormat, x).
return FormatDateTime(isolate, date_time_format, x);
return FormatDateTime(
isolate, *(date_time_format->icu_simple_date_format()->raw()), x);
}
namespace {
......@@ -903,6 +943,7 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::Initialize(
Managed<icu::SimpleDateFormat>::FromUniquePtr(isolate, 0,
std::move(date_format));
date_time_format->set_icu_simple_date_format(*managed_format);
return date_time_format;
}
......
......@@ -69,8 +69,7 @@ class JSDateTimeFormat : public JSObject {
V8_WARN_UNUSED_RESULT static MaybeHandle<String> ToLocaleDateTime(
Isolate* isolate, Handle<Object> date, Handle<Object> locales,
Handle<Object> options, RequiredOption required, DefaultsOption defaults,
Intl::CacheType cache_type);
Handle<Object> options, RequiredOption required, DefaultsOption defaults);
static std::set<std::string> GetAvailableLocales();
......
......@@ -483,14 +483,9 @@ Handle<String> JSNumberFormat::CurrencyDisplayAsString() const {
}
MaybeHandle<String> JSNumberFormat::FormatNumber(
Isolate* isolate, Handle<JSNumberFormat> number_format_holder,
double number) {
icu::NumberFormat* number_format =
number_format_holder->icu_number_format()->raw();
CHECK_NOT_NULL(number_format);
Isolate* isolate, const icu::NumberFormat& number_format, double number) {
icu::UnicodeString result;
number_format->format(number, result);
number_format.format(number, result);
return isolate->factory()->NewStringFromTwoByte(Vector<const uint16_t>(
reinterpret_cast<const uint16_t*>(result.getBuffer()), result.length()));
......
......@@ -59,7 +59,7 @@ class JSNumberFormat : public JSObject {
const icu::NumberFormat& fmt, double number, Handle<String> unit);
V8_WARN_UNUSED_RESULT static MaybeHandle<String> FormatNumber(
Isolate* isolate, Handle<JSNumberFormat> number_format, double number);
Isolate* isolate, const icu::NumberFormat& number_format, double number);
static std::set<std::string> GetAvailableLocales();
......
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