Commit 598ad028 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] clean up Locale code

Bug: v8:7684
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: I9c727e2d8b9efad09fdf712655ea367560cd971f
Reviewed-on: https://chromium-review.googlesource.com/c/1263655
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56421}
parent ca3220c6
...@@ -553,37 +553,45 @@ MaybeHandle<JSLocale> CreateLocale(Isolate* isolate, ...@@ -553,37 +553,45 @@ MaybeHandle<JSLocale> CreateLocale(Isolate* isolate,
Handle<JSFunction> constructor, Handle<JSFunction> constructor,
Handle<JSReceiver> new_target, Handle<JSReceiver> new_target,
Handle<Object> tag, Handle<Object> options) { Handle<Object> tag, Handle<Object> options) {
Handle<JSObject> result; Handle<JSObject> locale;
// 6. Let locale be ? OrdinaryCreateFromConstructor(NewTarget,
// %LocalePrototype%, internalSlotsList).
ASSIGN_RETURN_ON_EXCEPTION( ASSIGN_RETURN_ON_EXCEPTION(
isolate, result, isolate, locale,
JSObject::New(constructor, new_target, Handle<AllocationSite>::null()), JSObject::New(constructor, new_target, Handle<AllocationSite>::null()),
JSLocale); JSLocale);
// First parameter is a locale, as a string/object. Can't be empty. // 7. If Type(tag) is not String or Object, throw a TypeError exception.
if (!tag->IsString() && !tag->IsJSReceiver()) { if (!tag->IsString() && !tag->IsJSReceiver()) {
THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kLocaleNotEmpty), THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kLocaleNotEmpty),
JSLocale); JSLocale);
} }
Handle<String> locale_string; Handle<String> locale_string;
// 8. If Type(tag) is Object and tag has an [[InitializedLocale]] internal
// slot, then
if (tag->IsJSLocale() && Handle<JSLocale>::cast(tag)->locale()->IsString()) { if (tag->IsJSLocale() && Handle<JSLocale>::cast(tag)->locale()->IsString()) {
// a. Let tag be tag.[[Locale]].
locale_string = locale_string =
Handle<String>(Handle<JSLocale>::cast(tag)->locale(), isolate); Handle<String>(Handle<JSLocale>::cast(tag)->locale(), isolate);
} else { } else { // 9. Else,
// a. Let tag be ? ToString(tag).
ASSIGN_RETURN_ON_EXCEPTION(isolate, locale_string, ASSIGN_RETURN_ON_EXCEPTION(isolate, locale_string,
Object::ToString(isolate, tag), JSLocale); Object::ToString(isolate, tag), JSLocale);
} }
Handle<JSReceiver> options_object; Handle<JSReceiver> options_object;
if (options->IsNullOrUndefined(isolate)) { // 10. If options is undefined, then
// Make empty options bag. if (options->IsUndefined(isolate)) {
// a. Let options be ! ObjectCreate(null).
options_object = isolate->factory()->NewJSObjectWithNullProto(); options_object = isolate->factory()->NewJSObjectWithNullProto();
} else { } else { // 11. Else
// a. Let options be ? ToObject(options).
ASSIGN_RETURN_ON_EXCEPTION(isolate, options_object, ASSIGN_RETURN_ON_EXCEPTION(isolate, options_object,
Object::ToObject(isolate, options), JSLocale); Object::ToObject(isolate, options), JSLocale);
} }
return JSLocale::Initialize(isolate, Handle<JSLocale>::cast(result), return JSLocale::Initialize(isolate, Handle<JSLocale>::cast(locale),
locale_string, options_object); locale_string, options_object);
} }
......
...@@ -75,7 +75,7 @@ Maybe<bool> InsertOptionsIntoLocale(Isolate* isolate, ...@@ -75,7 +75,7 @@ Maybe<bool> InsertOptionsIntoLocale(Isolate* isolate,
: Intl::GetStringOption(isolate, options, option_to_bcp47.name, : Intl::GetStringOption(isolate, options, option_to_bcp47.name,
*(option_to_bcp47.possible_values), *(option_to_bcp47.possible_values),
"locale", &value_str); "locale", &value_str);
if (maybe_found.IsNothing()) return maybe_found; MAYBE_RETURN(maybe_found, Nothing<bool>());
// TODO(cira): Use fallback value if value is not found to make // TODO(cira): Use fallback value if value is not found to make
// this spec compliant. // this spec compliant.
...@@ -197,7 +197,6 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate, ...@@ -197,7 +197,6 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate,
isolate->factory()->NewStringFromAsciiChecked(kMethod), isolate->factory()->NewStringFromAsciiChecked(kMethod),
locale_holder), locale_holder),
JSLocale); JSLocale);
return MaybeHandle<JSLocale>();
} }
Maybe<bool> error = InsertOptionsIntoLocale(isolate, options, icu_result); Maybe<bool> error = InsertOptionsIntoLocale(isolate, options, icu_result);
...@@ -209,9 +208,7 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate, ...@@ -209,9 +208,7 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate,
isolate->factory()->NewStringFromAsciiChecked(kMethod), isolate->factory()->NewStringFromAsciiChecked(kMethod),
locale_holder), locale_holder),
JSLocale); JSLocale);
return MaybeHandle<JSLocale>();
} }
DCHECK(error.FromJust());
if (!PopulateLocaleWithUnicodeTags(isolate, icu_result, locale_holder)) { if (!PopulateLocaleWithUnicodeTags(isolate, icu_result, locale_holder)) {
THROW_NEW_ERROR( THROW_NEW_ERROR(
...@@ -220,7 +217,6 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate, ...@@ -220,7 +217,6 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate,
isolate->factory()->NewStringFromAsciiChecked(kMethod), isolate->factory()->NewStringFromAsciiChecked(kMethod),
locale_holder), locale_holder),
JSLocale); JSLocale);
return MaybeHandle<JSLocale>();
} }
// Extract language, script and region parts. // Extract language, script and region parts.
...@@ -240,7 +236,6 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate, ...@@ -240,7 +236,6 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate,
isolate->factory()->NewStringFromAsciiChecked(kMethod), isolate->factory()->NewStringFromAsciiChecked(kMethod),
locale_holder), locale_holder),
JSLocale); JSLocale);
return MaybeHandle<JSLocale>();
} }
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
...@@ -274,7 +269,6 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate, ...@@ -274,7 +269,6 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate,
isolate->factory()->NewStringFromAsciiChecked(kMethod), isolate->factory()->NewStringFromAsciiChecked(kMethod),
locale_holder), locale_holder),
JSLocale); JSLocale);
return MaybeHandle<JSLocale>();
} }
Handle<String> base_name = factory->NewStringFromAsciiChecked(bcp47_result); Handle<String> base_name = factory->NewStringFromAsciiChecked(bcp47_result);
locale_holder->set_base_name(*base_name); locale_holder->set_base_name(*base_name);
...@@ -289,7 +283,6 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate, ...@@ -289,7 +283,6 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate,
isolate->factory()->NewStringFromAsciiChecked(kMethod), isolate->factory()->NewStringFromAsciiChecked(kMethod),
locale_holder), locale_holder),
JSLocale); JSLocale);
return MaybeHandle<JSLocale>();
} }
Handle<String> locale_handle = Handle<String> locale_handle =
factory->NewStringFromAsciiChecked(bcp47_result); factory->NewStringFromAsciiChecked(bcp47_result);
......
...@@ -585,7 +585,6 @@ ...@@ -585,7 +585,6 @@
'intl402/Locale/constructor-options-script-invalid': [FAIL], 'intl402/Locale/constructor-options-script-invalid': [FAIL],
'intl402/Locale/constructor-options-script-valid': [FAIL], 'intl402/Locale/constructor-options-script-valid': [FAIL],
'intl402/Locale/getters': [FAIL], 'intl402/Locale/getters': [FAIL],
'intl402/Locale/invalid-tag-throws': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=8243 # https://bugs.chromium.org/p/v8/issues/detail?id=8243
'intl402/Locale/extensions-private': [FAIL], 'intl402/Locale/extensions-private': [FAIL],
......
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