LibJS: Don't assume non-empty [[Value]] in Completion TRY() helpers

This commit is contained in:
Linus Groh 2021-12-28 17:57:09 +01:00
parent 032e6a2d28
commit 95acb1ce88
Notes: sideshowbarker 2024-07-17 21:44:43 +09:00
8 changed files with 10 additions and 9 deletions

View file

@ -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 {};
}));

View file

@ -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) };
}

View file

@ -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 {};

View file

@ -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()));

View file

@ -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()));

View file

@ -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 {};
}));

View file

@ -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()));

View file

@ -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 {};
}));