diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp index b163f15118..d1c72bbb11 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -132,7 +132,7 @@ ThrowCompletionOr species_constructor(GlobalObject& global_obje } // 7.3.24 GetFunctionRealm ( obj ), https://tc39.es/ecma262/#sec-getfunctionrealm -Realm* get_function_realm(GlobalObject& global_object, FunctionObject const& function) +ThrowCompletionOr get_function_realm(GlobalObject& global_object, FunctionObject const& function) { auto& vm = global_object.vm(); @@ -160,10 +160,8 @@ Realm* get_function_realm(GlobalObject& global_object, FunctionObject const& fun auto& proxy = static_cast(function); // a. If obj.[[ProxyHandler]] is null, throw a TypeError exception. - if (proxy.is_revoked()) { - vm.throw_exception(global_object, ErrorType::ProxyRevoked); - return nullptr; - } + if (proxy.is_revoked()) + return vm.throw_completion(global_object, ErrorType::ProxyRevoked); // b. Let proxyTarget be obj.[[ProxyTarget]]. auto& proxy_target = proxy.target(); @@ -340,9 +338,7 @@ Object* get_prototype_from_constructor(GlobalObject& global_object, FunctionObje if (vm.exception()) return nullptr; if (!prototype.is_object()) { - auto* realm = get_function_realm(global_object, constructor); - if (vm.exception()) - return nullptr; + auto* realm = TRY_OR_DISCARD(get_function_realm(global_object, constructor)); prototype = (realm->global_object().*intrinsic_default_prototype)(); } return &prototype.as_object(); diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h index 51c6541560..f96f8600aa 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h @@ -23,7 +23,7 @@ ThrowCompletionOr require_object_coercible(GlobalObject&, Value); size_t length_of_array_like(GlobalObject&, Object const&); ThrowCompletionOr create_list_from_array_like(GlobalObject&, Value, Function(Value)> = {}); ThrowCompletionOr species_constructor(GlobalObject&, Object const&, FunctionObject& default_constructor); -Realm* get_function_realm(GlobalObject&, FunctionObject const&); +ThrowCompletionOr get_function_realm(GlobalObject&, FunctionObject const&); bool is_compatible_property_descriptor(bool extensible, PropertyDescriptor const&, Optional const& current); bool validate_and_apply_property_descriptor(Object*, PropertyName const&, bool extensible, PropertyDescriptor const&, Optional const& current); Object* get_prototype_from_constructor(GlobalObject&, FunctionObject const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)()); diff --git a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp index 774d500550..668ac59ef9 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -124,9 +124,7 @@ static Object* array_species_create(GlobalObject& global_object, Object& origina if (constructor.is_constructor()) { auto& constructor_function = constructor.as_function(); auto* this_realm = vm.current_realm(); - auto* constructor_realm = get_function_realm(global_object, constructor_function); - if (vm.exception()) - return {}; + auto* constructor_realm = TRY_OR_DISCARD(get_function_realm(global_object, constructor_function)); if (constructor_realm != this_realm) { if (&constructor_function == constructor_realm->global_object().array_constructor()) constructor = js_undefined();