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

LibJS: Remove GlobalObject from VM::throw_completion()

This is a continuation of the previous five commits.

A first big step into the direction of no longer having to pass a realm
(or currently, a global object) trough layers upon layers of AOs!
Unlike the create() APIs we can safely assume that this is only ever
called when a running execution context and therefore current realm
exists. If not, you can always manually allocate the Error and put it in
a Completion :^)

In the spec, throw exceptions implicitly use the current realm's
intrinsics as well: https://tc39.es/ecma262/#sec-throw-an-exception
This commit is contained in:
Linus Groh 2022-08-16 20:33:17 +01:00
parent 5398dcc55e
commit f3117d46dc
165 changed files with 892 additions and 900 deletions

View file

@ -229,7 +229,7 @@ ThrowCompletionOr<Vector<String>> canonicalize_locale_list(GlobalObject& global_
// ii. If Type(kValue) is not String or Object, throw a TypeError exception.
if (!key_value.is_string() && !key_value.is_object())
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObjectOrString, key_value.to_string_without_side_effects());
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOrString, key_value.to_string_without_side_effects());
String tag;
@ -247,7 +247,7 @@ ThrowCompletionOr<Vector<String>> canonicalize_locale_list(GlobalObject& global_
// 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);
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidLanguageTag, tag);
// vi. Let canonicalizedTag be ! CanonicalizeUnicodeLocaleId(tag).
auto canonicalized_tag = JS::Intl::canonicalize_unicode_locale_id(*locale_id);
@ -658,7 +658,7 @@ ThrowCompletionOr<Optional<int>> default_number_option(GlobalObject& global_obje
// 3. If value is NaN or less than minimum or greater than maximum, throw a RangeError exception.
if (value.is_nan() || (value.as_double() < minimum) || (value.as_double() > maximum))
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlNumberIsNaNOrOutOfRange, value, minimum, maximum);
return vm.throw_completion<RangeError>(ErrorType::IntlNumberIsNaNOrOutOfRange, value, minimum, maximum);
// 4. Return floor(value).
return floor(value.as_double());

View file

@ -52,7 +52,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(GlobalObject& global_obj
if (!collation.is_undefined()) {
// a. If collation does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
if (!Unicode::is_type_identifier(collation.as_string().string()))
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, collation, "collation"sv);
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, collation, "collation"sv);
// 12. Set opt.[[co]] to collation.
opt.co = collation.as_string().string();

View file

@ -119,13 +119,13 @@ ThrowCompletionOr<Object*> to_date_time_options(GlobalObject& global_object, Val
// 9. If required is "date" and timeStyle is not undefined, then
if ((required == OptionRequired::Date) && !time_style.is_undefined()) {
// a. Throw a TypeError exception.
return vm.throw_completion<TypeError>(global_object, ErrorType::IntlInvalidDateTimeFormatOption, "timeStyle"sv, "date"sv);
return vm.throw_completion<TypeError>(ErrorType::IntlInvalidDateTimeFormatOption, "timeStyle"sv, "date"sv);
}
// 10. If required is "time" and dateStyle is not undefined, then
if ((required == OptionRequired::Time) && !date_style.is_undefined()) {
// a. Throw a TypeError exception.
return vm.throw_completion<TypeError>(global_object, ErrorType::IntlInvalidDateTimeFormatOption, "dateStyle"sv, "time"sv);
return vm.throw_completion<TypeError>(ErrorType::IntlInvalidDateTimeFormatOption, "dateStyle"sv, "time"sv);
}
// 11. If needDefaults is true and defaults is either "date" or "all", then
@ -540,7 +540,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(GlobalObjec
// 2. If x is NaN, throw a RangeError exception.
if (isnan(time))
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlInvalidTime);
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidTime);
// 3. Let locale be dateTimeFormat.[[Locale]].
auto const& locale = date_time_format.locale();
@ -928,14 +928,14 @@ ThrowCompletionOr<Vector<PatternPartitionWithSource>> partition_date_time_range_
// 2. If x is NaN, throw a RangeError exception.
if (isnan(start))
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlInvalidTime);
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidTime);
// 3. Let y be TimeClip(y).
end = time_clip(end);
// 4. If y is NaN, throw a RangeError exception.
if (isnan(end))
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlInvalidTime);
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidTime);
// 5. Let tm1 be ToLocalTime(x, dateTimeFormat.[[Calendar]], dateTimeFormat.[[TimeZone]]).
auto start_local_time = TRY(to_local_time(global_object, start, date_time_format.calendar(), date_time_format.time_zone()));
@ -1248,7 +1248,7 @@ ThrowCompletionOr<LocalTime> to_local_time(GlobalObject& global_object, double t
// 3. Else,
// a. Return a record with the fields of Column 1 of Table 7 calculated from t for the given calendar and timeZone. The calculations should use best available information about the specified calendar and timeZone, including current and historical information about time zone offsets from UTC and daylight saving time rules.
// FIXME: Implement this when non-Gregorian calendars are supported by LibUnicode.
return global_object.vm().throw_completion<InternalError>(global_object, ErrorType::NotImplemented, "Non-Gregorian calendars"sv);
return global_object.vm().throw_completion<InternalError>(ErrorType::NotImplemented, "Non-Gregorian calendars"sv);
}
}

View file

@ -109,7 +109,7 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(GlobalObject& glo
if (!calendar.is_undefined()) {
// a. If calendar does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
if (!Unicode::is_type_identifier(calendar.as_string().string()))
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, calendar, "calendar"sv);
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, calendar, "calendar"sv);
// 8. Set opt.[[ca]] to calendar.
opt.ca = calendar.as_string().string();
@ -122,7 +122,7 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(GlobalObject& glo
if (!numbering_system.is_undefined()) {
// a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
if (!Unicode::is_type_identifier(numbering_system.as_string().string()))
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv);
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv);
// 11. Set opt.[[nu]] to numberingSystem.
opt.nu = numbering_system.as_string().string();
@ -229,7 +229,7 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(GlobalObject& glo
// b. If the result of IsValidTimeZoneName(timeZone) is false, then
if (!Temporal::is_valid_time_zone_name(time_zone)) {
// i. Throw a RangeError exception.
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, time_zone, vm.names.timeZone);
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, time_zone, vm.names.timeZone);
}
// c. Set timeZone to ! CanonicalizeTimeZoneName(timeZone).
@ -312,7 +312,7 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(GlobalObject& glo
// a. If hasExplicitFormatComponents is true, then
if (explicit_format_component != nullptr) {
// i. Throw a TypeError exception.
return vm.throw_completion<TypeError>(global_object, ErrorType::IntlInvalidDateTimeFormatOption, *explicit_format_component, "dateStyle or timeStyle"sv);
return vm.throw_completion<TypeError>(ErrorType::IntlInvalidDateTimeFormatOption, *explicit_format_component, "dateStyle or timeStyle"sv);
}
// b. Let styles be dataLocaleData.[[styles]].[[<resolvedCalendar>]].

View file

@ -100,9 +100,9 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_range)
// 3. If startDate is undefined or endDate is undefined, throw a TypeError exception.
if (start_date.is_undefined())
return vm.throw_completion<TypeError>(global_object, ErrorType::IsUndefined, "startDate"sv);
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "startDate"sv);
if (end_date.is_undefined())
return vm.throw_completion<TypeError>(global_object, ErrorType::IsUndefined, "endDate"sv);
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "endDate"sv);
// 4. Let x be ? ToNumber(startDate).
auto start_date_number = TRY(start_date.to_number(global_object)).as_double();
@ -127,9 +127,9 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_range_to_parts)
// 3. If startDate is undefined or endDate is undefined, throw a TypeError exception.
if (start_date.is_undefined())
return vm.throw_completion<TypeError>(global_object, ErrorType::IsUndefined, "startDate"sv);
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "startDate"sv);
if (end_date.is_undefined())
return vm.throw_completion<TypeError>(global_object, ErrorType::IsUndefined, "endDate"sv);
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "endDate"sv);
// 4. Let x be ? ToNumber(startDate).
auto start_date_number = TRY(start_date.to_number(global_object)).as_double();

View file

@ -109,12 +109,12 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(GlobalObject& global_o
if (type == DisplayNames::Type::Language) {
// a. If code does not match the unicode_language_id production, throw a RangeError exception.
if (!Unicode::parse_unicode_language_id(code).has_value())
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, code, "language"sv);
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "language"sv);
// b. If IsStructurallyValidLanguageTag(code) is false, throw a RangeError exception.
auto locale_id = is_structurally_valid_language_tag(code);
if (!locale_id.has_value())
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlInvalidLanguageTag, code);
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidLanguageTag, code);
// c. Return ! CanonicalizeUnicodeLocaleId(code).
auto canonicalized_tag = Intl::canonicalize_unicode_locale_id(*locale_id);
@ -125,7 +125,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(GlobalObject& global_o
if (type == DisplayNames::Type::Region) {
// a. If code does not match the unicode_region_subtag production, throw a RangeError exception.
if (!Unicode::is_unicode_region_subtag(code))
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, code, "region"sv);
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "region"sv);
// b. Return the ASCII-uppercase of code.
return js_string(vm, code.to_uppercase_string());
@ -135,7 +135,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(GlobalObject& global_o
if (type == DisplayNames::Type::Script) {
// a. If code does not match the unicode_script_subtag production, throw a RangeError exception.
if (!Unicode::is_unicode_script_subtag(code))
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, code, "script"sv);
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "script"sv);
// Assert: The length of code is 4, and every code unit of code represents an ASCII letter (0x0041 through 0x005A and 0x0061 through 0x007A, both inclusive).
VERIFY(code.length() == 4);
@ -151,11 +151,11 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(GlobalObject& global_o
if (type == DisplayNames::Type::Calendar) {
// a. If code does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
if (!Unicode::is_type_identifier(code))
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, code, "calendar"sv);
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "calendar"sv);
// b. If code uses any of the backwards compatibility syntax described in Unicode Technical Standard #35 LDML § 3.3 BCP 47 Conformance, throw a RangeError exception.
if (code.contains('_'))
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, code, "calendar"sv);
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "calendar"sv);
// c. Return the ASCII-lowercase of code.
return js_string(vm, code.to_lowercase_string());
@ -165,7 +165,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(GlobalObject& global_o
if (type == DisplayNames::Type::DateTimeField) {
// a. If the result of IsValidDateTimeFieldCode(code) is false, throw a RangeError exception.
if (!is_valid_date_time_field_code(code))
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, code, "dateTimeField"sv);
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "dateTimeField"sv);
// b. Return code.
return js_string(vm, code);
@ -176,7 +176,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(GlobalObject& global_o
// 7. If ! IsWellFormedCurrencyCode(code) is false, throw a RangeError exception.
if (!is_well_formed_currency_code(code))
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, code, "currency"sv);
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "currency"sv);
// 8. Return the ASCII-uppercase of code.
return js_string(vm, code.to_uppercase_string());

View file

@ -40,7 +40,7 @@ void DisplayNamesConstructor::initialize(Realm& realm)
ThrowCompletionOr<Value> DisplayNamesConstructor::call()
{
// 1. If NewTarget is undefined, throw a TypeError exception.
return vm().throw_completion<TypeError>(global_object(), ErrorType::ConstructorWithoutNew, "Intl.DisplayNames");
return vm().throw_completion<TypeError>(ErrorType::ConstructorWithoutNew, "Intl.DisplayNames");
}
// 12.1.1 Intl.DisplayNames ( locales, options ), https://tc39.es/ecma402/#sec-Intl.DisplayNames
@ -60,7 +60,7 @@ ThrowCompletionOr<Object*> DisplayNamesConstructor::construct(FunctionObject& ne
// 4. If options is undefined, throw a TypeError exception.
if (options_value.is_undefined())
return vm.throw_completion<TypeError>(global_object, ErrorType::IsUndefined, "options"sv);
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "options"sv);
// 5. Set options to ? GetOptionsObject(options).
auto* options = TRY(Temporal::get_options_object(global_object, options_value));
@ -90,7 +90,7 @@ ThrowCompletionOr<Object*> DisplayNamesConstructor::construct(FunctionObject& ne
// 14. If type is undefined, throw a TypeError exception.
if (type.is_undefined())
return vm.throw_completion<TypeError>(global_object, ErrorType::IsUndefined, "options.type"sv);
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "options.type"sv);
// 15. Set displayNames.[[Type]] to type.
display_names->set_type(type.as_string().string());

View file

@ -137,7 +137,7 @@ ThrowCompletionOr<Temporal::DurationRecord> to_duration_record(GlobalObject& glo
// 1. If Type(input) is not Object, throw a TypeError exception.
if (!input.is_object())
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObject, input);
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, input);
auto& input_object = input.as_object();
// 2. Let result be a new Record.
@ -177,7 +177,7 @@ ThrowCompletionOr<Temporal::DurationRecord> to_duration_record(GlobalObject& glo
// 5. If any is false, throw a TypeError exception.
if (!any)
return vm.throw_completion<TypeError>(global_object, ErrorType::TemporalInvalidDurationLikeObject);
return vm.throw_completion<TypeError>(ErrorType::TemporalInvalidDurationLikeObject);
// 6. Return result.
return result;
@ -281,7 +281,7 @@ ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(GlobalObject& g
// a. If style is not "numeric" or "2-digit", then
if (style != "numeric"sv && style != "2-digit"sv) {
// i. Throw a RangeError exception.
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlNonNumericOr2DigitAfterNumericOr2Digit);
return vm.throw_completion<RangeError>(ErrorType::IntlNonNumericOr2DigitAfterNumericOr2Digit);
}
// b. Else if unit is "minutes" or "seconds", then
else if (unit == "minutes"sv || unit == "seconds"sv) {

View file

@ -37,7 +37,7 @@ void DurationFormatConstructor::initialize(Realm& realm)
ThrowCompletionOr<Value> DurationFormatConstructor::call()
{
// 1. If NewTarget is undefined, throw a TypeError exception.
return vm().throw_completion<TypeError>(global_object(), ErrorType::ConstructorWithoutNew, "Intl.DurationFormat");
return vm().throw_completion<TypeError>(ErrorType::ConstructorWithoutNew, "Intl.DurationFormat");
}
// 1.2.1 Intl.DurationFormat ( [ locales [ , options ] ] ), https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat
@ -68,7 +68,7 @@ ThrowCompletionOr<Object*> DurationFormatConstructor::construct(FunctionObject&
if (!numbering_system.is_undefined()) {
// 7. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
if (numbering_system.is_undefined() || !Unicode::is_type_identifier(numbering_system.as_string().string()))
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv);
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv);
}
// 8. Let opt be the Record { [[localeMatcher]]: matcher, [[nu]]: numberingSystem }.

View file

@ -43,7 +43,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format)
// 4. If IsValidDurationRecord(record) is false, throw a RangeError exception.
if (!is_valid_duration_record(record))
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidDurationLikeObject);
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDurationLikeObject);
// 5. Let formatted be ? PartitionDurationFormatPattern(df, record).
auto formatted = TRY(partition_duration_format_pattern(global_object, *duration_format, record));
@ -75,7 +75,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
// 4. If IsValidDurationRecord(record) is false, throw a RangeError exception.
if (!is_valid_duration_record(record))
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidDurationLikeObject);
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidDurationLikeObject);
// 5. Let formatted be ? PartitionDurationFormatPattern(df, record).
auto formatted = TRY(partition_duration_format_pattern(global_object, *duration_format, record));

View file

@ -151,7 +151,7 @@ JS_DEFINE_NATIVE_FUNCTION(Intl::supported_values_of)
// 8. Else,
else {
// a. Throw a RangeError exception.
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlInvalidKey, key);
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidKey, key);
}
// 9. Return CreateArrayFromList( list ).

View file

@ -270,7 +270,7 @@ ThrowCompletionOr<Vector<String>> string_list_from_iterable(GlobalObject& global
// ii. If Type(nextValue) is not String, then
if (!next_value.is_string()) {
// 1. Let error be ThrowCompletion(a newly created TypeError object).
auto error = vm.throw_completion<TypeError>(global_object, ErrorType::NotAString, next_value);
auto error = vm.throw_completion<TypeError>(ErrorType::NotAString, next_value);
// 2. Return ? IteratorClose(iteratorRecord, error).
return iterator_close(global_object, iterator_record, move(error));

View file

@ -39,7 +39,7 @@ void ListFormatConstructor::initialize(Realm& realm)
ThrowCompletionOr<Value> ListFormatConstructor::call()
{
// 1. If NewTarget is undefined, throw a TypeError exception.
return vm().throw_completion<TypeError>(global_object(), ErrorType::ConstructorWithoutNew, "Intl.ListFormat");
return vm().throw_completion<TypeError>(ErrorType::ConstructorWithoutNew, "Intl.ListFormat");
}
// 13.1.1 Intl.ListFormat ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sec-Intl.ListFormat

View file

@ -35,7 +35,7 @@ static ThrowCompletionOr<Optional<String>> get_string_option(GlobalObject& globa
return Optional<String> {};
if (validator && !validator(option.as_string().string()))
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, option, property);
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, option, property);
return option.as_string().string();
}
@ -51,7 +51,7 @@ static ThrowCompletionOr<String> apply_options_to_tag(GlobalObject& global_objec
// 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);
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidLanguageTag, tag);
// 4. Let language be ? GetOption(options, "language", "string", undefined, undefined).
// 5. If language is not undefined, then
@ -240,7 +240,7 @@ void LocaleConstructor::initialize(Realm& realm)
ThrowCompletionOr<Value> LocaleConstructor::call()
{
// 1. If NewTarget is undefined, throw a TypeError exception.
return vm().throw_completion<TypeError>(global_object(), ErrorType::ConstructorWithoutNew, "Intl.Locale");
return vm().throw_completion<TypeError>(ErrorType::ConstructorWithoutNew, "Intl.Locale");
}
// 14.1.1 Intl.Locale ( tag [ , options ] ), https://tc39.es/ecma402/#sec-Intl.Locale
@ -268,7 +268,7 @@ ThrowCompletionOr<Object*> LocaleConstructor::construct(FunctionObject& new_targ
// 7. If Type(tag) is not String or Object, throw a TypeError exception.
if (!tag_value.is_string() && !tag_value.is_object())
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObjectOrString, "tag"sv);
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOrString, "tag"sv);
// 8. If Type(tag) is Object and tag has an [[InitializedLocale]] internal slot, then
if (tag_value.is_object() && is<Locale>(tag_value.as_object())) {

View file

@ -1726,9 +1726,9 @@ ThrowCompletionOr<Vector<PatternPartitionWithSource>> partition_number_range_pat
// 1. If x is NaN or y is NaN, throw a RangeError exception.
if (start.is_nan())
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlNumberIsNaN, "start"sv);
return vm.throw_completion<RangeError>(ErrorType::IntlNumberIsNaN, "start"sv);
if (end.is_nan())
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlNumberIsNaN, "end"sv);
return vm.throw_completion<RangeError>(ErrorType::IntlNumberIsNaN, "end"sv);
// 2. Let result be a new empty List.
Vector<PatternPartitionWithSource> result;

View file

@ -107,7 +107,7 @@ ThrowCompletionOr<NumberFormat*> initialize_number_format(GlobalObject& global_o
if (!numbering_system.is_undefined()) {
// a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
if (!Unicode::is_type_identifier(numbering_system.as_string().string()))
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv);
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv);
// 8. Set opt.[[nu]] to numberingSystem.
opt.nu = numbering_system.as_string().string();
@ -178,15 +178,15 @@ ThrowCompletionOr<NumberFormat*> initialize_number_format(GlobalObject& global_o
static constexpr auto sanctioned_rounding_increments = AK::Array { 1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000 };
if (!sanctioned_rounding_increments.span().contains_slow(*rounding_increment))
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlInvalidRoundingIncrement, *rounding_increment);
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidRoundingIncrement, *rounding_increment);
// 23. If roundingIncrement is not 1 and numberFormat.[[RoundingType]] is not fractionDigits, throw a TypeError exception.
if ((rounding_increment != 1) && (number_format.rounding_type() != NumberFormatBase::RoundingType::FractionDigits))
return vm.throw_completion<TypeError>(global_object, ErrorType::IntlInvalidRoundingIncrementForRoundingType, *rounding_increment, number_format.rounding_type_string());
return vm.throw_completion<TypeError>(ErrorType::IntlInvalidRoundingIncrementForRoundingType, *rounding_increment, number_format.rounding_type_string());
// 24. If roundingIncrement is not 1 and numberFormat.[[MaximumFractionDigits]] is not equal to numberFormat.[[MinimumFractionDigits]], throw a RangeError exception.
if ((rounding_increment != 1) && (number_format.max_fraction_digits() != number_format.min_fraction_digits()))
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlInvalidRoundingIncrementForFractionDigits, *rounding_increment);
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidRoundingIncrementForFractionDigits, *rounding_increment);
// 25. Set numberFormat.[[RoundingIncrement]] to roundingIncrement.
number_format.set_rounding_increment(*rounding_increment);
@ -335,7 +335,7 @@ ThrowCompletionOr<void> set_number_format_digit_options(GlobalObject& global_obj
max_digits = max(default_max_fraction_digits, *min_digits);
// v. Else if mnfd is greater than mxfd, throw a RangeError exception.
else if (*min_digits > *max_digits)
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlMinimumExceedsMaximum, *min_digits, *max_digits);
return vm.throw_completion<RangeError>(ErrorType::IntlMinimumExceedsMaximum, *min_digits, *max_digits);
// vi. Set intlObj.[[MinimumFractionDigits]] to mnfd.
intl_object.set_min_fraction_digits(*min_digits);
@ -419,12 +419,12 @@ ThrowCompletionOr<void> set_number_format_unit_options(GlobalObject& global_obje
if (currency.is_undefined()) {
// a. If style is "currency", throw a TypeError exception.
if (intl_object.style() == NumberFormat::Style::Currency)
return vm.throw_completion<TypeError>(global_object, ErrorType::IntlOptionUndefined, "currency"sv, "style"sv, style);
return vm.throw_completion<TypeError>(ErrorType::IntlOptionUndefined, "currency"sv, "style"sv, style);
}
// 7. Else,
// a. If ! IsWellFormedCurrencyCode(currency) is false, throw a RangeError exception.
else if (!is_well_formed_currency_code(currency.as_string().string()))
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, currency, "currency"sv);
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, currency, "currency"sv);
// 8. Let currencyDisplay be ? GetOption(options, "currencyDisplay", "string", « "code", "symbol", "narrowSymbol", "name" », "symbol").
auto currency_display = TRY(get_option(global_object, options, vm.names.currencyDisplay, OptionType::String, { "code"sv, "symbol"sv, "narrowSymbol"sv, "name"sv }, "symbol"sv));
@ -439,12 +439,12 @@ ThrowCompletionOr<void> set_number_format_unit_options(GlobalObject& global_obje
if (unit.is_undefined()) {
// a. If style is "unit", throw a TypeError exception.
if (intl_object.style() == NumberFormat::Style::Unit)
return vm.throw_completion<TypeError>(global_object, ErrorType::IntlOptionUndefined, "unit"sv, "style"sv, style);
return vm.throw_completion<TypeError>(ErrorType::IntlOptionUndefined, "unit"sv, "style"sv, style);
}
// 12. Else,
// a. If ! IsWellFormedUnitIdentifier(unit) is false, throw a RangeError exception.
else if (!is_well_formed_unit_identifier(unit.as_string().string()))
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, unit, "unit"sv);
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, unit, "unit"sv);
// 13. Let unitDisplay be ? GetOption(options, "unitDisplay", "string", « "short", "narrow", "long" », "short").
auto unit_display = TRY(get_option(global_object, options, vm.names.unitDisplay, OptionType::String, { "short"sv, "narrow"sv, "long"sv }, "short"sv));

View file

@ -92,9 +92,9 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format_range)
// 3. If start is undefined or end is undefined, throw a TypeError exception.
if (start.is_undefined())
return vm.throw_completion<TypeError>(global_object, ErrorType::IsUndefined, "start"sv);
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "start"sv);
if (end.is_undefined())
return vm.throw_completion<TypeError>(global_object, ErrorType::IsUndefined, "end"sv);
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "end"sv);
// 4. Let x be ? ToIntlMathematicalValue(start).
auto x = TRY(to_intl_mathematical_value(global_object, start));
@ -119,9 +119,9 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format_range_to_parts)
// 3. If start is undefined or end is undefined, throw a TypeError exception.
if (start.is_undefined())
return vm.throw_completion<TypeError>(global_object, ErrorType::IsUndefined, "start"sv);
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "start"sv);
if (end.is_undefined())
return vm.throw_completion<TypeError>(global_object, ErrorType::IsUndefined, "end"sv);
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "end"sv);
// 4. Let x be ? ToIntlMathematicalValue(start).
auto x = TRY(to_intl_mathematical_value(global_object, start));

View file

@ -148,9 +148,9 @@ ThrowCompletionOr<Unicode::PluralCategory> resolve_plural_range(GlobalObject& gl
// 5. If x is NaN or y is NaN, throw a RangeError exception.
if (start.is_nan())
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlNumberIsNaN, "start"sv);
return vm.throw_completion<RangeError>(ErrorType::IntlNumberIsNaN, "start"sv);
if (end.is_nan())
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlNumberIsNaN, "end"sv);
return vm.throw_completion<RangeError>(ErrorType::IntlNumberIsNaN, "end"sv);
// 6. Let xp be ! ResolvePlural(pluralRules, x).
auto start_plurality = resolve_plural(plural_rules, start);

View file

@ -39,7 +39,7 @@ void PluralRulesConstructor::initialize(Realm& realm)
ThrowCompletionOr<Value> PluralRulesConstructor::call()
{
// 1. If NewTarget is undefined, throw a TypeError exception.
return vm().throw_completion<TypeError>(global_object(), ErrorType::ConstructorWithoutNew, "Intl.PluralRules");
return vm().throw_completion<TypeError>(ErrorType::ConstructorWithoutNew, "Intl.PluralRules");
}
// 16.1.1 Intl.PluralRules ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sec-intl.pluralrules

View file

@ -60,9 +60,9 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::select_range)
// 3. If start is undefined or end is undefined, throw a TypeError exception.
if (start.is_undefined())
return vm.throw_completion<TypeError>(global_object, ErrorType::IsUndefined, "start"sv);
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "start"sv);
if (end.is_undefined())
return vm.throw_completion<TypeError>(global_object, ErrorType::IsUndefined, "end"sv);
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, "end"sv);
// 4. Let x be ? ToNumber(start).
auto x = TRY(start.to_number(global_object));

View file

@ -89,7 +89,7 @@ ThrowCompletionOr<Unicode::TimeUnit> singular_relative_time_unit(GlobalObject& g
// 11. Return unit.
if (auto time_unit = Unicode::time_unit_from_string(unit); time_unit.has_value())
return *time_unit;
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlInvalidUnit, unit);
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidUnit, unit);
}
// 17.5.2 PartitionRelativeTimePattern ( relativeTimeFormat, value, unit ), https://tc39.es/ecma402/#sec-PartitionRelativeTimePattern
@ -103,7 +103,7 @@ ThrowCompletionOr<Vector<PatternPartitionWithUnit>> partition_relative_time_patt
// 4. If value is NaN, +∞𝔽, or -∞𝔽, throw a RangeError exception.
if (!Value(value).is_finite_number())
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlNumberIsNaNOrInfinity);
return vm.throw_completion<RangeError>(ErrorType::IntlNumberIsNaNOrInfinity);
// 5. Let unit be ? SingularRelativeTimeUnit(unit).
auto time_unit = TRY(singular_relative_time_unit(global_object, unit));

View file

@ -42,7 +42,7 @@ void RelativeTimeFormatConstructor::initialize(Realm& realm)
ThrowCompletionOr<Value> RelativeTimeFormatConstructor::call()
{
// 1. If NewTarget is undefined, throw a TypeError exception.
return vm().throw_completion<TypeError>(global_object(), ErrorType::ConstructorWithoutNew, "Intl.RelativeTimeFormat");
return vm().throw_completion<TypeError>(ErrorType::ConstructorWithoutNew, "Intl.RelativeTimeFormat");
}
// 17.1.1 Intl.RelativeTimeFormat ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat
@ -103,7 +103,7 @@ ThrowCompletionOr<RelativeTimeFormat*> initialize_relative_time_format(GlobalObj
if (!numbering_system.is_undefined()) {
// a. If numberingSystem does not match the Unicode Locale Identifier type nonterminal, throw a RangeError exception.
if (!Unicode::is_type_identifier(numbering_system.as_string().string()))
return vm.throw_completion<RangeError>(global_object, ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv);
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv);
// 8. Set opt.[[nu]] to numberingSystem.
opt.nu = numbering_system.as_string().string();

View file

@ -38,7 +38,7 @@ void SegmenterConstructor::initialize(Realm& realm)
ThrowCompletionOr<Value> SegmenterConstructor::call()
{
// 1. If NewTarget is undefined, throw a TypeError exception.
return vm().throw_completion<TypeError>(global_object(), ErrorType::ConstructorWithoutNew, "Intl.Segmenter");
return vm().throw_completion<TypeError>(ErrorType::ConstructorWithoutNew, "Intl.Segmenter");
}
// 18.1.1 Intl.Segmenter ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sec-intl.segmenter