1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 20:18:12 +00:00

LibJS: Convert Value::get() to ThrowCompletionOr

This commit is contained in:
Idan Horowitz 2021-10-18 23:34:28 +03:00 committed by Linus Groh
parent 72b409a2f7
commit c15a3b0576
3 changed files with 7 additions and 13 deletions

View file

@ -733,16 +733,16 @@ ThrowCompletionOr<double> Value::to_integer_or_infinity(GlobalObject& global_obj
}
// 7.3.3 GetV ( V, P ), https://tc39.es/ecma262/#sec-getv
Value Value::get(GlobalObject& global_object, PropertyName const& property_name) const
ThrowCompletionOr<Value> Value::get(GlobalObject& global_object, PropertyName const& property_name) const
{
// 1. Assert: IsPropertyKey(P) is true.
VERIFY(property_name.is_valid());
// 2. Let O be ? ToObject(V).
auto* object = TRY_OR_DISCARD(to_object(global_object));
auto* object = TRY(to_object(global_object));
// 3. Return ? O.[[Get]](P, V).
return TRY_OR_DISCARD(object->internal_get(property_name, *this));
return TRY(object->internal_get(property_name, *this));
}
// 7.3.10 GetMethod ( V, P ), https://tc39.es/ecma262/#sec-getmethod
@ -754,9 +754,7 @@ ThrowCompletionOr<FunctionObject*> Value::get_method(GlobalObject& global_object
VERIFY(property_name.is_valid());
// 2. Let func be ? GetV(V, P).
auto function = get(global_object, property_name);
if (auto* exception = vm.exception())
return throw_completion(exception->value());
auto function = TRY(get(global_object, property_name));
// 3. If func is either undefined or null, return undefined.
if (function.is_nullish())
@ -1485,9 +1483,7 @@ TriState is_less_than(GlobalObject& global_object, bool left_first, Value lhs, V
ThrowCompletionOr<Value> Value::invoke_internal(GlobalObject& global_object, JS::PropertyName const& property_name, Optional<MarkedValueList> arguments)
{
auto& vm = global_object.vm();
auto property = get(global_object, property_name);
if (auto* exception = vm.exception())
return throw_completion(exception->value());
auto property = TRY(get(global_object, property_name));
if (!property.is_function())
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, property.to_string_without_side_effects());