mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:27:35 +00:00
LibJS: Convert Value::get() to ThrowCompletionOr
This commit is contained in:
parent
72b409a2f7
commit
c15a3b0576
3 changed files with 7 additions and 13 deletions
|
@ -27,9 +27,7 @@ static Value get_promise_resolve(GlobalObject& global_object, Value constructor)
|
||||||
VERIFY(constructor.is_constructor());
|
VERIFY(constructor.is_constructor());
|
||||||
auto& vm = global_object.vm();
|
auto& vm = global_object.vm();
|
||||||
|
|
||||||
auto promise_resolve = constructor.get(global_object, vm.names.resolve);
|
auto promise_resolve = TRY_OR_DISCARD(constructor.get(global_object, vm.names.resolve));
|
||||||
if (vm.exception())
|
|
||||||
return {};
|
|
||||||
if (!promise_resolve.is_function()) {
|
if (!promise_resolve.is_function()) {
|
||||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunction, promise_resolve.to_string_without_side_effects());
|
vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunction, promise_resolve.to_string_without_side_effects());
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -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
|
// 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.
|
// 1. Assert: IsPropertyKey(P) is true.
|
||||||
VERIFY(property_name.is_valid());
|
VERIFY(property_name.is_valid());
|
||||||
|
|
||||||
// 2. Let O be ? ToObject(V).
|
// 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).
|
// 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
|
// 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());
|
VERIFY(property_name.is_valid());
|
||||||
|
|
||||||
// 2. Let func be ? GetV(V, P).
|
// 2. Let func be ? GetV(V, P).
|
||||||
auto function = get(global_object, property_name);
|
auto function = TRY(get(global_object, property_name));
|
||||||
if (auto* exception = vm.exception())
|
|
||||||
return throw_completion(exception->value());
|
|
||||||
|
|
||||||
// 3. If func is either undefined or null, return undefined.
|
// 3. If func is either undefined or null, return undefined.
|
||||||
if (function.is_nullish())
|
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)
|
ThrowCompletionOr<Value> Value::invoke_internal(GlobalObject& global_object, JS::PropertyName const& property_name, Optional<MarkedValueList> arguments)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
auto& vm = global_object.vm();
|
||||||
auto property = get(global_object, property_name);
|
auto property = TRY(get(global_object, property_name));
|
||||||
if (auto* exception = vm.exception())
|
|
||||||
return throw_completion(exception->value());
|
|
||||||
if (!property.is_function())
|
if (!property.is_function())
|
||||||
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, property.to_string_without_side_effects());
|
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, property.to_string_without_side_effects());
|
||||||
|
|
||||||
|
|
|
@ -327,7 +327,7 @@ public:
|
||||||
ThrowCompletionOr<double> to_integer_or_infinity(GlobalObject&) const;
|
ThrowCompletionOr<double> to_integer_or_infinity(GlobalObject&) const;
|
||||||
bool to_boolean() const;
|
bool to_boolean() const;
|
||||||
|
|
||||||
Value get(GlobalObject&, PropertyName const&) const;
|
ThrowCompletionOr<Value> get(GlobalObject&, PropertyName const&) const;
|
||||||
ThrowCompletionOr<FunctionObject*> get_method(GlobalObject&, PropertyName const&) const;
|
ThrowCompletionOr<FunctionObject*> get_method(GlobalObject&, PropertyName const&) const;
|
||||||
|
|
||||||
String to_string_without_side_effects() const;
|
String to_string_without_side_effects() const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue