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

@ -22,7 +22,7 @@ ThrowCompletionOr<void> Reference::put_value(GlobalObject& global_object, Value
// 3. If V is not a Reference Record, throw a ReferenceError exception.
if (!is_valid_reference())
return vm.throw_completion<ReferenceError>(global_object, ErrorType::InvalidLeftHandAssignment);
return vm.throw_completion<ReferenceError>(ErrorType::InvalidLeftHandAssignment);
// 4. If IsUnresolvableReference(V) is true, then
if (is_unresolvable()) {
@ -54,7 +54,7 @@ ThrowCompletionOr<void> Reference::put_value(GlobalObject& global_object, Value
// d. If succeeded is false and V.[[Strict]] is true, throw a TypeError exception.
if (!succeeded && m_strict)
return vm.throw_completion<TypeError>(global_object, ErrorType::ReferenceNullishSetProperty, m_name, m_base_value.to_string_without_side_effects());
return vm.throw_completion<TypeError>(ErrorType::ReferenceNullishSetProperty, m_name, m_base_value.to_string_without_side_effects());
// e. Return unused.
return {};
@ -78,9 +78,9 @@ Completion Reference::throw_reference_error(GlobalObject& global_object) const
{
auto& vm = global_object.vm();
if (!m_name.is_valid())
return vm.throw_completion<ReferenceError>(global_object, ErrorType::ReferenceUnresolvable);
return vm.throw_completion<ReferenceError>(ErrorType::ReferenceUnresolvable);
else
return vm.throw_completion<ReferenceError>(global_object, ErrorType::UnknownIdentifier, m_name.to_string_or_symbol().to_display_string());
return vm.throw_completion<ReferenceError>(ErrorType::UnknownIdentifier, m_name.to_string_or_symbol().to_display_string());
}
// 6.2.4.5 GetValue ( V ), https://tc39.es/ecma262/#sec-getvalue
@ -170,7 +170,7 @@ ThrowCompletionOr<bool> Reference::delete_(GlobalObject& global_object)
// b. If IsSuperReference(ref) is true, throw a ReferenceError exception.
if (is_super_reference())
return vm.throw_completion<ReferenceError>(global_object, ErrorType::UnsupportedDeleteSuperProperty);
return vm.throw_completion<ReferenceError>(ErrorType::UnsupportedDeleteSuperProperty);
// c. Let baseObj be ! ToObject(ref.[[Base]]).
auto* base_obj = MUST(m_base_value.to_object(global_object));
@ -180,7 +180,7 @@ ThrowCompletionOr<bool> Reference::delete_(GlobalObject& global_object)
// e. If deleteStatus is false and ref.[[Strict]] is true, throw a TypeError exception.
if (!delete_status && m_strict)
return vm.throw_completion<TypeError>(global_object, ErrorType::ReferenceNullishDeleteProperty, m_name, m_base_value.to_string_without_side_effects());
return vm.throw_completion<TypeError>(ErrorType::ReferenceNullishDeleteProperty, m_name, m_base_value.to_string_without_side_effects());
// f. Return deleteStatus.
return delete_status;