1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:07:35 +00:00

LibJS: Explicitly indicate infallible incovations

These are editorial changes in the Intl spec.

See:
6804096
6361167
8718171
fd37cb4
00fcfb0
913f832
This commit is contained in:
Timothy Flynn 2022-03-28 08:30:48 -04:00 committed by Linus Groh
parent 278241859b
commit 7c41e6058a
11 changed files with 37 additions and 37 deletions

View file

@ -201,7 +201,7 @@ ThrowCompletionOr<Vector<String>> canonicalize_locale_list(GlobalObject& global_
Object* object = nullptr;
// 3. If Type(locales) is String or Type(locales) is Object and locales has an [[InitializedLocale]] internal slot, then
if (locales.is_string() || (locales.is_object() && is<Locale>(locales.as_object()))) {
// a. Let O be CreateArrayFromList(« locales »).
// a. Let O be ! CreateArrayFromList(« locales »).
object = Array::create_from(global_object, { locales });
}
// 4. Else,
@ -245,12 +245,12 @@ ThrowCompletionOr<Vector<String>> canonicalize_locale_list(GlobalObject& global_
tag = TRY(key_value.to_string(global_object));
}
// v. If IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception.
// v. If ! IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception.
auto locale_id = is_structurally_valid_language_tag(tag);
if (!locale_id.has_value())
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlInvalidLanguageTag, tag);
// vi. Let canonicalizedTag be CanonicalizeUnicodeLocaleId(tag).
// vi. Let canonicalizedTag be ! CanonicalizeUnicodeLocaleId(tag).
auto canonicalized_tag = JS::Intl::canonicalize_unicode_locale_id(*locale_id);
// vii. If canonicalizedTag is not an element of seen, append canonicalizedTag as the last element of seen.
@ -310,7 +310,7 @@ static MatcherResult lookup_matcher(Vector<String> const& requested_locales)
auto extensions = locale_id->remove_extension_type<Unicode::LocaleExtension>();
auto no_extensions_locale = locale_id->to_string();
// b. Let availableLocale be BestAvailableLocale(availableLocales, noExtensionsLocale).
// b. Let availableLocale be ! BestAvailableLocale(availableLocales, noExtensionsLocale).
auto available_locale = best_available_locale(no_extensions_locale);
// c. If availableLocale is not undefined, then
@ -330,7 +330,7 @@ static MatcherResult lookup_matcher(Vector<String> const& requested_locales)
}
}
// 3. Let defLocale be DefaultLocale().
// 3. Let defLocale be ! DefaultLocale().
// 4. Set result.[[locale]] to defLocale.
result.locale = Unicode::default_locale();
@ -386,12 +386,12 @@ LocaleResult resolve_locale(Vector<String> const& requested_locales, LocaleOptio
// 2. If matcher is "lookup", then
if (matcher.is_string() && (matcher.as_string().string() == "lookup"sv)) {
// a. Let r be LookupMatcher(availableLocales, requestedLocales).
// a. Let r be ! LookupMatcher(availableLocales, requestedLocales).
matcher_result = lookup_matcher(requested_locales);
}
// 3. Else,
else {
// a. Let r be BestFitMatcher(availableLocales, requestedLocales).
// a. Let r be ! BestFitMatcher(availableLocales, requestedLocales).
matcher_result = best_fit_matcher(requested_locales);
}
@ -540,7 +540,7 @@ Vector<String> lookup_supported_locales(Vector<String> const& requested_locales)
locale_id->remove_extension_type<Unicode::LocaleExtension>();
auto no_extensions_locale = locale_id->to_string();
// b. Let availableLocale be BestAvailableLocale(availableLocales, noExtensionsLocale).
// b. Let availableLocale be ! BestAvailableLocale(availableLocales, noExtensionsLocale).
auto available_locale = best_available_locale(no_extensions_locale);
// c. If availableLocale is not undefined, append locale to the end of subset.
@ -588,7 +588,7 @@ ThrowCompletionOr<Array*> supported_locales(GlobalObject& global_object, Vector<
supported_locales = lookup_supported_locales(requested_locales);
}
// 5. Return CreateArrayFromList(supportedLocales).
// 5. Return ! CreateArrayFromList(supportedLocales).
return Array::create_from<String>(global_object, supported_locales, [&vm](auto& locale) { return js_string(vm, locale); });
}

View file

@ -72,7 +72,7 @@ ThrowCompletionOr<Object*> to_date_time_options(GlobalObject& global_object, Val
if (!options_value.is_undefined())
options = TRY(options_value.to_object(global_object));
// 2. Let options be OrdinaryObjectCreate(options).
// 2. Let options be ! OrdinaryObjectCreate(options).
options = Object::create(global_object, options);
// 3. Let needDefaults be true.
@ -524,7 +524,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(GlobalObjec
return static_cast<NumberFormat*>(number_format);
};
// 4. Let nfOptions be OrdinaryObjectCreate(null).
// 4. Let nfOptions be ! OrdinaryObjectCreate(null).
auto* number_format_options = Object::create(global_object, nullptr);
// 5. Perform ! CreateDataPropertyOrThrow(nfOptions, "useGrouping", false).
@ -533,7 +533,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(GlobalObjec
// 6. Let nf be ? Construct(%NumberFormat%, « locale, nfOptions »).
auto* number_format = TRY(construct_number_format(number_format_options));
// 7. Let nf2Options be OrdinaryObjectCreate(null).
// 7. Let nf2Options be ! OrdinaryObjectCreate(null).
auto* number_format_options2 = Object::create(global_object, nullptr);
// 8. Perform ! CreateDataPropertyOrThrow(nf2Options, "minimumIntegerDigits", 2).
@ -553,7 +553,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(GlobalObjec
if (date_time_format.has_fractional_second_digits()) {
fractional_second_digits = date_time_format.fractional_second_digits();
// a. Let nf3Options be OrdinaryObjectCreate(null).
// a. Let nf3Options be ! OrdinaryObjectCreate(null).
auto* number_format_options3 = Object::create(global_object, nullptr);
// b. Perform ! CreateDataPropertyOrThrow(nf3Options, "minimumIntegerDigits", fractionalSecondDigits).
@ -827,7 +827,7 @@ ThrowCompletionOr<Array*> format_date_time_to_parts(GlobalObject& global_object,
// 1. Let parts be ? PartitionDateTimePattern(dateTimeFormat, x).
auto parts = TRY(partition_date_time_pattern(global_object, date_time_format, time));
// 2. Let result be ArrayCreate(0).
// 2. Let result be ! ArrayCreate(0).
auto* result = MUST(Array::create(global_object, 0));
// 3. Let n be 0.
@ -835,7 +835,7 @@ ThrowCompletionOr<Array*> format_date_time_to_parts(GlobalObject& global_object,
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
// a. Let O be ! OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(global_object, global_object.object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
@ -1147,7 +1147,7 @@ ThrowCompletionOr<Array*> format_date_time_range_to_parts(GlobalObject& global_o
// 1. Let parts be ? PartitionDateTimeRangePattern(dateTimeFormat, x, y).
auto parts = TRY(partition_date_time_range_pattern(global_object, date_time_format, start, end));
// 2. Let result be ArrayCreate(0).
// 2. Let result be ! ArrayCreate(0).
auto* result = MUST(Array::create(global_object, 0));
// 3. Let n be 0.
@ -1155,7 +1155,7 @@ ThrowCompletionOr<Array*> format_date_time_range_to_parts(GlobalObject& global_o
// 4. For each Record { [[Type]], [[Value]], [[Source]] } part in parts, do
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%ObjectPrototype%).
// a. Let O be ! OrdinaryObjectCreate(%ObjectPrototype%).
auto* object = Object::create(global_object, global_object.object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).

View file

@ -46,7 +46,7 @@ ThrowCompletionOr<Value> DateTimeFormatFunction::call()
// 3. If date is not provided or is undefined, then
if (date.is_undefined()) {
// a. Let x be Call(%Date.now%, undefined).
// a. Let x be ! Call(%Date.now%, undefined).
date = MUST(JS::call(global_object, global_object.date_constructor_now_function(), js_undefined()));
}
// 4. Else,

View file

@ -71,7 +71,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_to_parts)
// 3. If date is undefined, then
if (date.is_undefined()) {
// a. Let x be Call(%Date.now%, undefined).
// a. Let x be ! Call(%Date.now%, undefined).
date = MUST(call(global_object, global_object.date_constructor_now_function(), js_undefined()));
}
// 4. Else,

View file

@ -69,7 +69,7 @@ JS_DEFINE_NATIVE_FUNCTION(Intl::get_canonical_locales)
for (auto& locale : locale_list)
marked_locale_list.append(js_string(vm, move(locale)));
// 2. Return CreateArrayFromList(ll).
// 2. Return ! CreateArrayFromList(ll).
return Array::create_from(global_object, marked_locale_list);
}

View file

@ -48,7 +48,7 @@ StringView ListFormat::type_string() const
// 13.5.1 DeconstructPattern ( pattern, placeables ), https://tc39.es/ecma402/#sec-deconstructpattern
Vector<PatternPartition> deconstruct_pattern(StringView pattern, Placeables placeables)
{
// 1. Let patternParts be PartitionPattern(pattern).
// 1. Let patternParts be ! PartitionPattern(pattern).
auto pattern_parts = partition_pattern(pattern);
// 2. Let result be a new empty List.
@ -125,7 +125,7 @@ Vector<PatternPartition> create_parts_from_list(ListFormat const& list_format, V
placeables.set("0"sv, move(first));
placeables.set("1"sv, move(second));
// f. Return DeconstructPattern(pattern, placeables).
// f. Return ! DeconstructPattern(pattern, placeables).
return deconstruct_pattern(pattern, move(placeables));
}
@ -171,7 +171,7 @@ Vector<PatternPartition> create_parts_from_list(ListFormat const& list_format, V
placeables.set("0"sv, move(head));
placeables.set("1"sv, move(parts));
// g. Set parts to DeconstructPattern(pattern, placeables).
// g. Set parts to ! DeconstructPattern(pattern, placeables).
parts = deconstruct_pattern(pattern, move(placeables));
// h. Decrement i by 1.
@ -184,7 +184,7 @@ Vector<PatternPartition> create_parts_from_list(ListFormat const& list_format, V
// 13.5.3 FormatList ( listFormat, list ), https://tc39.es/ecma402/#sec-formatlist
String format_list(ListFormat const& list_format, Vector<String> const& list)
{
// 1. Let parts be CreatePartsFromList(listFormat, list).
// 1. Let parts be ! CreatePartsFromList(listFormat, list).
auto parts = create_parts_from_list(list_format, list);
// 2. Let result be an empty String.
@ -205,10 +205,10 @@ Array* format_list_to_parts(GlobalObject& global_object, ListFormat const& list_
{
auto& vm = global_object.vm();
// 1. Let parts be CreatePartsFromList(listFormat, list).
// 1. Let parts be ! CreatePartsFromList(listFormat, list).
auto parts = create_parts_from_list(list_format, list);
// 2. Let result be ArrayCreate(0).
// 2. Let result be ! ArrayCreate(0).
auto* result = MUST(Array::create(global_object, 0));
// 3. Let n be 0.
@ -216,7 +216,7 @@ Array* format_list_to_parts(GlobalObject& global_object, ListFormat const& list_
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
// a. Let O be ! OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(global_object, global_object.object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).

View file

@ -45,7 +45,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::format)
// 3. Let stringList be ? StringListFromIterable(list).
auto string_list = TRY(string_list_from_iterable(global_object, list));
// 4. Return FormatList(lf, stringList).
// 4. Return ! FormatList(lf, stringList).
auto formatted = format_list(*list_format, string_list);
return js_string(vm, move(formatted));
}
@ -62,7 +62,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::format_to_parts)
// 3. Let stringList be ? StringListFromIterable(list).
auto string_list = TRY(string_list_from_iterable(global_object, list));
// 4. Return FormatListToParts(lf, stringList).
// 4. Return ! FormatListToParts(lf, stringList).
return format_list_to_parts(global_object, *list_format, string_list);
}

View file

@ -48,7 +48,7 @@ static ThrowCompletionOr<String> apply_options_to_tag(GlobalObject& global_objec
// 1. Assert: Type(tag) is String.
// 2. Assert: Type(options) is Object.
// 3. If IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception.
// 3. If ! IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception.
auto locale_id = is_structurally_valid_language_tag(tag);
if (!locale_id.has_value())
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlInvalidLanguageTag, tag);
@ -68,7 +68,7 @@ static ThrowCompletionOr<String> apply_options_to_tag(GlobalObject& global_objec
// a. If region does not match the unicode_region_subtag production, throw a RangeError exception.
auto region = TRY(get_string_option(global_object, options, vm.names.region, Unicode::is_unicode_region_subtag));
// 10. Set tag to CanonicalizeUnicodeLocaleId(tag).
// 10. Set tag to ! CanonicalizeUnicodeLocaleId(tag).
auto canonicalized_tag = JS::Intl::canonicalize_unicode_locale_id(*locale_id);
// 11. Assert: tag matches the unicode_locale_id production.
@ -103,7 +103,7 @@ static ThrowCompletionOr<String> apply_options_to_tag(GlobalObject& global_objec
}
// 16. Set tag to tag with the substring corresponding to the unicode_language_id production replaced by the string languageId.
// 17. Return CanonicalizeUnicodeLocaleId(tag).
// 17. Return ! CanonicalizeUnicodeLocaleId(tag).
return JS::Intl::canonicalize_unicode_locale_id(*locale_id);
}

View file

@ -809,7 +809,7 @@ Array* format_numeric_to_parts(GlobalObject& global_object, NumberFormat& number
// Note: Our implementation of PartitionNumberPattern does not throw.
auto parts = partition_number_pattern(global_object, number_format, number);
// 2. Let result be ArrayCreate(0).
// 2. Let result be ! ArrayCreate(0).
auto* result = MUST(Array::create(global_object, 0));
// 3. Let n be 0.
@ -817,7 +817,7 @@ Array* format_numeric_to_parts(GlobalObject& global_object, NumberFormat& number
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
// a. Let O be ! OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(global_object, global_object.object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).

View file

@ -61,7 +61,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
// FIXME: Implement this when the data is available in LibUnicode.
MarkedVector<Value> plural_categories { vm.heap() };
// 6. Perform ! CreateDataProperty(options, "pluralCategories", CreateArrayFromList(pluralCategories)).
// 6. Perform ! CreateDataProperty(options, "pluralCategories", ! CreateArrayFromList(pluralCategories)).
MUST(options->create_data_property_or_throw(vm.names.pluralCategories, Array::create_from(global_object, plural_categories)));
// 7. Return options.

View file

@ -249,7 +249,7 @@ ThrowCompletionOr<Array*> format_relative_time_to_parts(GlobalObject& global_obj
// 1. Let parts be ? PartitionRelativeTimePattern(relativeTimeFormat, value, unit).
auto parts = TRY(partition_relative_time_pattern(global_object, relative_time_format, value, unit));
// 2. Let result be ArrayCreate(0).
// 2. Let result be ! ArrayCreate(0).
auto* result = MUST(Array::create(global_object, 0));
// 3. Let n be 0.
@ -257,7 +257,7 @@ ThrowCompletionOr<Array*> format_relative_time_to_parts(GlobalObject& global_obj
// 4. For each Record { [[Type]], [[Value]], [[Unit]] } part in parts, do
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
// a. Let O be ! OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(global_object, global_object.object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).