diff options
author | Michaël Zasso <targos@protonmail.com> | 2020-07-13 10:39:42 +0200 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2020-07-13 14:41:41 +0200 |
commit | 12478684aab233942e0d5dc24f195930c8a5e59d (patch) | |
tree | 97dbee955ab91d4df480bcb82274d710a2195e64 /deps/v8/src/objects/js-locale.cc | |
parent | 913d36d97da187a3804f6cfa96b4d24a8b7be78a (diff) | |
download | node-new-12478684aab233942e0d5dc24f195930c8a5e59d.tar.gz |
deps: update V8 to 8.4.371.19
PR-URL: https://github.com/nodejs/node/pull/33579
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
Diffstat (limited to 'deps/v8/src/objects/js-locale.cc')
-rw-r--r-- | deps/v8/src/objects/js-locale.cc | 61 |
1 files changed, 35 insertions, 26 deletions
diff --git a/deps/v8/src/objects/js-locale.cc b/deps/v8/src/objects/js-locale.cc index 6bbb86a0b1..53738049d9 100644 --- a/deps/v8/src/objects/js-locale.cc +++ b/deps/v8/src/objects/js-locale.cc @@ -365,38 +365,47 @@ MaybeHandle<JSLocale> JSLocale::New(Isolate* isolate, Handle<Map> map, } namespace { -Handle<String> MorphLocale(Isolate* isolate, String locale, - void (*morph_func)(icu::Locale*, UErrorCode*)) { - UErrorCode status = U_ZERO_ERROR; - icu::Locale icu_locale = - icu::Locale::forLanguageTag(locale.ToCString().get(), status); - // TODO(ftang): Remove the following lines after ICU-8420 fixed. - // Due to ICU-8420 "und" is turn into "" by forLanguageTag, - // we have to work around to use icu::Locale("und") directly - if (icu_locale.getName()[0] == '\0') icu_locale = icu::Locale("und"); - CHECK(U_SUCCESS(status)); - CHECK(!icu_locale.isBogus()); - (*morph_func)(&icu_locale, &status); - CHECK(U_SUCCESS(status)); - CHECK(!icu_locale.isBogus()); - std::string locale_str = Intl::ToLanguageTag(icu_locale).FromJust(); - return isolate->factory()->NewStringFromAsciiChecked(locale_str.c_str()); + +MaybeHandle<JSLocale> Construct(Isolate* isolate, + const icu::Locale& icu_locale) { + Handle<Managed<icu::Locale>> managed_locale = + Managed<icu::Locale>::FromRawPtr(isolate, 0, icu_locale.clone()); + + Handle<JSFunction> constructor( + isolate->native_context()->intl_locale_function(), isolate); + + Handle<Map> map; + ASSIGN_RETURN_ON_EXCEPTION( + isolate, map, + JSFunction::GetDerivedMap(isolate, constructor, constructor), JSLocale); + + Handle<JSLocale> locale = Handle<JSLocale>::cast( + isolate->factory()->NewFastOrSlowJSObjectFromMap(map)); + DisallowHeapAllocation no_gc; + locale->set_icu_locale(*managed_locale); + return locale; } } // namespace -Handle<String> JSLocale::Maximize(Isolate* isolate, String locale) { - return MorphLocale(isolate, locale, - [](icu::Locale* icu_locale, UErrorCode* status) { - icu_locale->addLikelySubtags(*status); - }); +MaybeHandle<JSLocale> JSLocale::Maximize(Isolate* isolate, + Handle<JSLocale> locale) { + icu::Locale icu_locale(*(locale->icu_locale().raw())); + UErrorCode status = U_ZERO_ERROR; + icu_locale.addLikelySubtags(status); + DCHECK(U_SUCCESS(status)); + DCHECK(!icu_locale.isBogus()); + return Construct(isolate, icu_locale); } -Handle<String> JSLocale::Minimize(Isolate* isolate, String locale) { - return MorphLocale(isolate, locale, - [](icu::Locale* icu_locale, UErrorCode* status) { - icu_locale->minimizeSubtags(*status); - }); +MaybeHandle<JSLocale> JSLocale::Minimize(Isolate* isolate, + Handle<JSLocale> locale) { + icu::Locale icu_locale(*(locale->icu_locale().raw())); + UErrorCode status = U_ZERO_ERROR; + icu_locale.minimizeSubtags(status); + DCHECK(U_SUCCESS(status)); + DCHECK(!icu_locale.isBogus()); + return Construct(isolate, icu_locale); } Handle<Object> JSLocale::Language(Isolate* isolate, Handle<JSLocale> locale) { |