From 95acb1ce885b2d2b833e6f4e3b12dfd41b50bc80 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 28 Dec 2021 17:57:09 +0100 Subject: LibJS: Don't assume non-empty [[Value]] in Completion TRY() helpers --- Userland/Libraries/LibJS/AST.cpp | 4 ++-- Userland/Libraries/LibJS/Runtime/Completion.h | 3 ++- Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp | 2 +- Userland/Libraries/LibJS/Runtime/MapConstructor.cpp | 2 +- Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp | 2 +- Userland/Libraries/LibJS/Runtime/SetConstructor.cpp | 2 +- Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp | 2 +- Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp | 2 +- 8 files changed, 10 insertions(+), 9 deletions(-) (limited to 'Userland') diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index a98c7e5674..4da5201576 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -888,7 +888,7 @@ Value ForOfStatement::execute(Interpreter& interpreter, GlobalObject& global_obj interpreter.vm().running_execution_context().lexical_environment = old_environment; }); - TRY_OR_DISCARD(get_iterator_values(global_object, rhs_result, [&](Value value) -> Optional { + (void)TRY_OR_DISCARD(get_iterator_values(global_object, rhs_result, [&](Value value) -> Optional { TRY(for_of_head_state.execute_head(interpreter, global_object, value)); last_value = m_body->execute(interpreter, global_object).value_or(last_value); interpreter.vm().running_execution_context().lexical_environment = old_environment; @@ -2973,7 +2973,7 @@ Value ArrayExpression::execute(Interpreter& interpreter, GlobalObject& global_ob return {}; if (is(*element)) { - TRY_OR_DISCARD(get_iterator_values(global_object, value, [&](Value iterator_value) -> Optional { + (void)TRY_OR_DISCARD(get_iterator_values(global_object, value, [&](Value iterator_value) -> Optional { array->indexed_properties().put(index++, iterator_value, default_attributes); return {}; })); diff --git a/Userland/Libraries/LibJS/Runtime/Completion.h b/Userland/Libraries/LibJS/Runtime/Completion.h index 6e55f69e8e..fc04a38b1d 100644 --- a/Userland/Libraries/LibJS/Runtime/Completion.h +++ b/Userland/Libraries/LibJS/Runtime/Completion.h @@ -70,10 +70,11 @@ public: // These are for compatibility with the TRY() macro in AK. [[nodiscard]] bool is_error() const { return m_type == Type::Throw; } - [[nodiscard]] Value release_value() { return m_value.release_value(); } + [[nodiscard]] Optional release_value() { return move(m_value); } Completion release_error() { VERIFY(is_error()); + VERIFY(m_value.has_value()); return { m_type, release_value(), move(m_target) }; } diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp index 75febaa11a..1e158e7e60 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp @@ -180,7 +180,7 @@ ThrowCompletionOr iterable_to_list(GlobalObject& global_object, auto& vm = global_object.vm(); MarkedValueList values(vm.heap()); - TRY(get_iterator_values( + (void)TRY(get_iterator_values( global_object, iterable, [&](auto value) -> Optional { values.append(value); return {}; diff --git a/Userland/Libraries/LibJS/Runtime/MapConstructor.cpp b/Userland/Libraries/LibJS/Runtime/MapConstructor.cpp index 3b173ee663..f4243e902a 100644 --- a/Userland/Libraries/LibJS/Runtime/MapConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/MapConstructor.cpp @@ -57,7 +57,7 @@ ThrowCompletionOr MapConstructor::construct(FunctionObject& new_target) if (!adder.is_function()) return vm.throw_completion(global_object, ErrorType::NotAFunction, "'set' property of Map"); - TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional { + (void)TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional { if (!iterator_value.is_object()) return vm.throw_completion(global_object, ErrorType::NotAnObject, String::formatted("Iterator value {}", iterator_value.to_string_without_side_effects())); diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp index 5ad4293a26..a2851992d0 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -226,7 +226,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::from_entries) auto* object = Object::create(global_object, global_object.object_prototype()); - TRY(get_iterator_values(global_object, iterable, [&](Value iterator_value) -> Optional { + (void)TRY(get_iterator_values(global_object, iterable, [&](Value iterator_value) -> Optional { if (!iterator_value.is_object()) return vm.throw_completion(global_object, ErrorType::NotAnObject, String::formatted("Iterator value {}", iterator_value.to_string_without_side_effects())); diff --git a/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp b/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp index 2ad10c5e23..7987986d0f 100644 --- a/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp @@ -57,7 +57,7 @@ ThrowCompletionOr SetConstructor::construct(FunctionObject& new_target) if (!adder.is_function()) return vm.throw_completion(global_object, ErrorType::NotAFunction, "'add' property of Set"); - TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional { + (void)TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional { TRY(vm.call(adder.as_function(), Value(set), iterator_value)); return {}; })); diff --git a/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp b/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp index c823920c15..1883acfbaf 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp @@ -55,7 +55,7 @@ ThrowCompletionOr WeakMapConstructor::construct(FunctionObject& new_tar if (!adder.is_function()) return vm.throw_completion(global_object, ErrorType::NotAFunction, "'set' property of WeakMap"); - TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional { + (void)TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional { if (!iterator_value.is_object()) return vm.throw_completion(global_object, ErrorType::NotAnObject, String::formatted("Iterator value {}", iterator_value.to_string_without_side_effects())); diff --git a/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp b/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp index bf2fec5147..07e13c3b2c 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp @@ -55,7 +55,7 @@ ThrowCompletionOr WeakSetConstructor::construct(FunctionObject& new_tar if (!adder.is_function()) return vm.throw_completion(global_object, ErrorType::NotAFunction, "'add' property of WeakSet"); - TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional { + (void)TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional { TRY(vm.call(adder.as_function(), Value(weak_set), iterator_value)); return {}; })); -- cgit v1.2.3