diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp index 22e98e2af2..73ba496167 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -59,7 +59,6 @@ void BytecodeInterpreter::branch_to_label(Configuration& configuration, LabelInd { dbgln_if(WASM_TRACE_DEBUG, "Branch to label with index {}...", index.value()); auto label = configuration.nth_label(index.value()); - TRAP_IF_NOT(label.has_value()); dbgln_if(WASM_TRACE_DEBUG, "...which is actually IP {}, and has {} result(s)", label->continuation().value(), label->arity()); auto results = pop_values(configuration, label->arity()); @@ -89,9 +88,7 @@ void BytecodeInterpreter::load_and_push(Configuration& configuration, Instructio return; } auto& arg = instruction.arguments().get(); - TRAP_IF_NOT(!configuration.stack().is_empty()); auto& entry = configuration.stack().peek(); - TRAP_IF_NOT(entry.has()); auto base = entry.get().to(); if (!base.has_value()) { m_trap = Trap { "Memory access out of bounds" }; @@ -115,18 +112,16 @@ void BytecodeInterpreter::call_address(Configuration& configuration, FunctionAdd TRAP_IF_NOT(m_stack_info.size_free() >= Constants::minimum_stack_space_to_keep_free); auto instance = configuration.store().get(address); - TRAP_IF_NOT(instance); FunctionType const* type { nullptr }; instance->visit([&](auto const& function) { type = &function.type(); }); - TRAP_IF_NOT(type); TRAP_IF_NOT(configuration.stack().entries().size() > type->parameters().size()); Vector args; args.ensure_capacity(type->parameters().size()); auto span = configuration.stack().entries().span().slice_from_end(type->parameters().size()); for (auto& entry : span) { - auto* ptr = entry.get_pointer(); - TRAP_IF_NOT(ptr != nullptr); - args.unchecked_append(move(*ptr)); + auto* call_argument = entry.get_pointer(); + TRAP_IF_NOT(call_argument); + args.unchecked_append(move(*call_argument)); } configuration.stack().entries().remove(configuration.stack().size() - span.size(), span.size()); @@ -150,17 +145,12 @@ void BytecodeInterpreter::call_address(Configuration& configuration, FunctionAdd template void BytecodeInterpreter::binary_numeric_operation(Configuration& configuration) { - TRAP_IF_NOT(!configuration.stack().is_empty()); auto rhs_entry = configuration.stack().pop(); auto& lhs_entry = configuration.stack().peek(); auto rhs_ptr = rhs_entry.get_pointer(); auto lhs_ptr = lhs_entry.get_pointer(); - TRAP_IF_NOT(rhs_ptr); - TRAP_IF_NOT(lhs_ptr); auto rhs = rhs_ptr->to(); auto lhs = lhs_ptr->to(); - TRAP_IF_NOT(lhs.has_value()); - TRAP_IF_NOT(rhs.has_value()); PushType result; auto call_result = Operator {}(lhs.value(), rhs.value()); if constexpr (IsSpecializationOf) { @@ -179,12 +169,9 @@ void BytecodeInterpreter::binary_numeric_operation(Configuration& configuration) template void BytecodeInterpreter::unary_operation(Configuration& configuration) { - TRAP_IF_NOT(!configuration.stack().is_empty()); auto& entry = configuration.stack().peek(); auto entry_ptr = entry.get_pointer(); - TRAP_IF_NOT(entry_ptr); auto value = entry_ptr->to(); - TRAP_IF_NOT(value.has_value()); auto call_result = Operator {}(*value); PushType result; if constexpr (IsSpecializationOf) { @@ -237,9 +224,7 @@ struct ConvertToRaw { template void BytecodeInterpreter::pop_and_store(Configuration& configuration, Instruction const& instruction) { - TRAP_IF_NOT(!configuration.stack().is_empty()); auto entry = configuration.stack().pop(); - TRAP_IF_NOT(entry.has()); auto value = ConvertToRaw {}(*entry.get().to()); dbgln_if(WASM_TRACE_DEBUG, "stack({}) -> temporary({}b)", value, sizeof(StoreT)); store_to_memory(configuration, instruction, { &value, sizeof(StoreT) }); @@ -249,13 +234,9 @@ void BytecodeInterpreter::store_to_memory(Configuration& configuration, Instruct { auto& address = configuration.frame().module().memories().first(); auto memory = configuration.store().get(address); - TRAP_IF_NOT(memory); auto& arg = instruction.arguments().get(); - TRAP_IF_NOT(!configuration.stack().is_empty()); auto entry = configuration.stack().pop(); - TRAP_IF_NOT(entry.has()); auto base = entry.get().to(); - TRAP_IF_NOT(base.has_value()); u64 instance_address = static_cast(bit_cast(base.value())) + arg.offset; Checked addition { instance_address }; addition += data.size(); @@ -377,9 +358,7 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi configuration.stack().push(Value(configuration.frame().locals()[instruction.arguments().get().value()])); return; case Instructions::local_set.value(): { - TRAP_IF_NOT(!configuration.stack().is_empty()); auto entry = configuration.stack().pop(); - TRAP_IF_NOT(entry.has()); configuration.frame().locals()[instruction.arguments().get().value()] = move(entry.get()); return; } @@ -417,11 +396,8 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi if (args.block_type.kind() != BlockType::Empty) arity = 1; - TRAP_IF_NOT(!configuration.stack().is_empty()); auto entry = configuration.stack().pop(); - TRAP_IF_NOT(entry.has()); auto value = entry.get().to(); - TRAP_IF_NOT(value.has_value()); auto end_label = Label(arity, args.end_ip.value()); if (value.value() == 0) { if (args.else_ip.has_value()) { @@ -438,7 +414,6 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi case Instructions::structured_end.value(): case Instructions::structured_else.value(): { auto index = configuration.nth_label_index(0); - TRAP_IF_NOT(index.has_value()); auto label = configuration.stack().entries()[*index].get