summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-10-18 23:34:28 +0300
committerLinus Groh <mail@linusgroh.de>2021-10-18 23:06:11 +0100
commitc15a3b0576a68761a91ac8d342ad45c9c815414a (patch)
treef6f817c4f5951ef213be1f01ec82ed31a5fe8c0d /Userland/Libraries/LibJS
parent72b409a2f7e63fe4f283788df8aba489278fcc2c (diff)
downloadserenity-c15a3b0576a68761a91ac8d342ad45c9c815414a.zip
LibJS: Convert Value::get() to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.cpp14
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.h2
3 files changed, 7 insertions, 13 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
index db041d3e88..7ca4096e0c 100644
--- a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp
@@ -27,9 +27,7 @@ static Value get_promise_resolve(GlobalObject& global_object, Value constructor)
VERIFY(constructor.is_constructor());
auto& vm = global_object.vm();
- auto promise_resolve = constructor.get(global_object, vm.names.resolve);
- if (vm.exception())
- return {};
+ auto promise_resolve = TRY_OR_DISCARD(constructor.get(global_object, vm.names.resolve));
if (!promise_resolve.is_function()) {
vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunction, promise_resolve.to_string_without_side_effects());
return {};
diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp
index 873428de97..d19b9916ba 100644
--- a/Userland/Libraries/LibJS/Runtime/Value.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Value.cpp
@@ -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());
diff --git a/Userland/Libraries/LibJS/Runtime/Value.h b/Userland/Libraries/LibJS/Runtime/Value.h
index 99bcccdeae..f0bac9cfcf 100644
--- a/Userland/Libraries/LibJS/Runtime/Value.h
+++ b/Userland/Libraries/LibJS/Runtime/Value.h
@@ -327,7 +327,7 @@ public:
ThrowCompletionOr<double> to_integer_or_infinity(GlobalObject&) 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;
String to_string_without_side_effects() const;