1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:27: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

@ -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())) {