summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-12-28 17:57:09 +0100
committerLinus Groh <mail@linusgroh.de>2022-01-03 21:50:50 +0100
commit95acb1ce885b2d2b833e6f4e3b12dfd41b50bc80 (patch)
treeecb732c41a50d7dbcc0635f66b86d78a03dbaffe /Userland/Libraries/LibJS
parent032e6a2d281008919ef8efd52c0d7b9d1784e60f (diff)
downloadserenity-95acb1ce885b2d2b833e6f4e3b12dfd41b50bc80.zip
LibJS: Don't assume non-empty [[Value]] in Completion TRY() helpers
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/AST.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Completion.h3
-rw-r--r--Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/MapConstructor.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/SetConstructor.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp2
8 files changed, 10 insertions, 9 deletions
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<Completion> {
+ (void)TRY_OR_DISCARD(get_iterator_values(global_object, rhs_result, [&](Value value) -> Optional<Completion> {
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<SpreadExpression>(*element)) {
- TRY_OR_DISCARD(get_iterator_values(global_object, value, [&](Value iterator_value) -> Optional<Completion> {
+ (void)TRY_OR_DISCARD(get_iterator_values(global_object, value, [&](Value iterator_value) -> Optional<Completion> {
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<Value> 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<MarkedValueList> 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<Completion> {
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<Object*> MapConstructor::construct(FunctionObject& new_target)
if (!adder.is_function())
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, "'set' property of Map");
- TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional<Completion> {
+ (void)TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional<Completion> {
if (!iterator_value.is_object())
return vm.throw_completion<TypeError>(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<Completion> {
+ (void)TRY(get_iterator_values(global_object, iterable, [&](Value iterator_value) -> Optional<Completion> {
if (!iterator_value.is_object())
return vm.throw_completion<TypeError>(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<Object*> SetConstructor::construct(FunctionObject& new_target)
if (!adder.is_function())
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, "'add' property of Set");
- TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional<Completion> {
+ (void)TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional<Completion> {
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<Object*> WeakMapConstructor::construct(FunctionObject& new_tar
if (!adder.is_function())
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, "'set' property of WeakMap");
- TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional<Completion> {
+ (void)TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional<Completion> {
if (!iterator_value.is_object())
return vm.throw_completion<TypeError>(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<Object*> WeakSetConstructor::construct(FunctionObject& new_tar
if (!adder.is_function())
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, "'add' property of WeakSet");
- TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional<Completion> {
+ (void)TRY(get_iterator_values(global_object, vm.argument(0), [&](Value iterator_value) -> Optional<Completion> {
TRY(vm.call(adder.as_function(), Value(weak_set), iterator_value));
return {};
}));