[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: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56421}
This commit is contained in:
Frank Tang 2018-10-05 18:06:11 -07:00 committed by Commit Bot
parent ca3220c649
commit 598ad02887
3 changed files with 17 additions and 17 deletions

View File

@ -553,37 +553,45 @@ MaybeHandle<JSLocale> CreateLocale(Isolate* isolate,
Handle<JSFunction> constructor,
Handle<JSReceiver> new_target,
Handle<Object> tag, Handle<Object> options) {
Handle<JSObject> result;
Handle<JSObject> locale;
// 6. Let locale be ? OrdinaryCreateFromConstructor(NewTarget,
// %LocalePrototype%, internalSlotsList).
ASSIGN_RETURN_ON_EXCEPTION(
isolate, result,
isolate, locale,
JSObject::New(constructor, new_target, Handle<AllocationSite>::null()),
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()) {
THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kLocaleNotEmpty),
JSLocale);
}
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()) {
// a. Let tag be tag.[[Locale]].
locale_string =
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,
Object::ToString(isolate, tag), JSLocale);
}
Handle<JSReceiver> options_object;
if (options->IsNullOrUndefined(isolate)) {
// Make empty options bag.
// 10. If options is undefined, then
if (options->IsUndefined(isolate)) {
// a. Let options be ! ObjectCreate(null).
options_object = isolate->factory()->NewJSObjectWithNullProto();
} else {
} else { // 11. Else
// a. Let options be ? ToObject(options).
ASSIGN_RETURN_ON_EXCEPTION(isolate, options_object,
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);
}

View File

@ -75,7 +75,7 @@ Maybe<bool> InsertOptionsIntoLocale(Isolate* isolate,
: Intl::GetStringOption(isolate, options, option_to_bcp47.name,
*(option_to_bcp47.possible_values),
"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
// this spec compliant.
@ -197,7 +197,6 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate,
isolate->factory()->NewStringFromAsciiChecked(kMethod),
locale_holder),
JSLocale);
return MaybeHandle<JSLocale>();
}
Maybe<bool> error = InsertOptionsIntoLocale(isolate, options, icu_result);
@ -209,9 +208,7 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate,
isolate->factory()->NewStringFromAsciiChecked(kMethod),
locale_holder),
JSLocale);
return MaybeHandle<JSLocale>();
}
DCHECK(error.FromJust());
if (!PopulateLocaleWithUnicodeTags(isolate, icu_result, locale_holder)) {
THROW_NEW_ERROR(
@ -220,7 +217,6 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate,
isolate->factory()->NewStringFromAsciiChecked(kMethod),
locale_holder),
JSLocale);
return MaybeHandle<JSLocale>();
}
// Extract language, script and region parts.
@ -240,7 +236,6 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate,
isolate->factory()->NewStringFromAsciiChecked(kMethod),
locale_holder),
JSLocale);
return MaybeHandle<JSLocale>();
}
Factory* factory = isolate->factory();
@ -274,7 +269,6 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate,
isolate->factory()->NewStringFromAsciiChecked(kMethod),
locale_holder),
JSLocale);
return MaybeHandle<JSLocale>();
}
Handle<String> base_name = factory->NewStringFromAsciiChecked(bcp47_result);
locale_holder->set_base_name(*base_name);
@ -289,7 +283,6 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate,
isolate->factory()->NewStringFromAsciiChecked(kMethod),
locale_holder),
JSLocale);
return MaybeHandle<JSLocale>();
}
Handle<String> locale_handle =
factory->NewStringFromAsciiChecked(bcp47_result);

View File

@ -585,7 +585,6 @@
'intl402/Locale/constructor-options-script-invalid': [FAIL],
'intl402/Locale/constructor-options-script-valid': [FAIL],
'intl402/Locale/getters': [FAIL],
'intl402/Locale/invalid-tag-throws': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=8243
'intl402/Locale/extensions-private': [FAIL],