1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:54:58 +00:00

LibWasm: Remove uses of AK::Result

Closes #23500.
This commit is contained in:
Ali Mohammad Pur 2024-03-11 22:57:59 +01:00 committed by Ali Mohammad Pur
parent 8003bde03d
commit 5a40ce442b
6 changed files with 14 additions and 14 deletions

View file

@ -551,7 +551,7 @@ void Linker::link(HashMap<Linker::Name, ExternValue> const& exports)
m_unresolved_imports.remove(entry); m_unresolved_imports.remove(entry);
} }
AK::Result<Vector<ExternValue>, LinkError> Linker::finish() AK::ErrorOr<Vector<ExternValue>, LinkError> Linker::finish()
{ {
populate(); populate();
if (!m_unresolved_imports.is_empty()) { if (!m_unresolved_imports.is_empty()) {

View file

@ -604,7 +604,7 @@ private:
Vector<EntryType, 1024> m_data; Vector<EntryType, 1024> m_data;
}; };
using InstantiationResult = AK::Result<NonnullOwnPtr<ModuleInstance>, InstantiationError>; using InstantiationResult = AK::ErrorOr<NonnullOwnPtr<ModuleInstance>, InstantiationError>;
class AbstractMachine { class AbstractMachine {
public: public:
@ -655,7 +655,7 @@ public:
return m_unresolved_imports; return m_unresolved_imports;
} }
AK::Result<Vector<ExternValue>, LinkError> finish(); AK::ErrorOr<Vector<ExternValue>, LinkError> finish();
private: private:
void populate(); void populate();

View file

@ -307,7 +307,7 @@ void BytecodeInterpreter::binary_numeric_operation(Configuration& configuration,
auto lhs = lhs_ptr->to<PopTypeLHS>(); auto lhs = lhs_ptr->to<PopTypeLHS>();
PushType result; PushType result;
auto call_result = Operator { forward<Args>(args)... }(lhs.value(), rhs.value()); auto call_result = Operator { forward<Args>(args)... }(lhs.value(), rhs.value());
if constexpr (IsSpecializationOf<decltype(call_result), AK::Result>) { if constexpr (IsSpecializationOf<decltype(call_result), AK::ErrorOr>) {
if (call_result.is_error()) { if (call_result.is_error()) {
trap_if_not(false, call_result.error()); trap_if_not(false, call_result.error());
return; return;
@ -328,7 +328,7 @@ void BytecodeInterpreter::unary_operation(Configuration& configuration, Args&&..
auto value = entry_ptr->to<PopType>(); auto value = entry_ptr->to<PopType>();
auto call_result = Operator { forward<Args>(args)... }(*value); auto call_result = Operator { forward<Args>(args)... }(*value);
PushType result; PushType result;
if constexpr (IsSpecializationOf<decltype(call_result), AK::Result>) { if constexpr (IsSpecializationOf<decltype(call_result), AK::ErrorOr>) {
if (call_result.is_error()) { if (call_result.is_error()) {
trap_if_not(false, call_result.error()); trap_if_not(false, call_result.error());
return; return;

View file

@ -58,8 +58,8 @@ struct Divide {
Checked value(lhs); Checked value(lhs);
value /= rhs; value /= rhs;
if (value.has_overflow()) if (value.has_overflow())
return AK::Result<Lhs, StringView>("Integer division overflow"sv); return AK::ErrorOr<Lhs, StringView>("Integer division overflow"sv);
return AK::Result<Lhs, StringView>(value.value()); return AK::ErrorOr<Lhs, StringView>(value.value());
} }
} }
@ -71,12 +71,12 @@ struct Modulo {
auto operator()(Lhs lhs, Rhs rhs) const auto operator()(Lhs lhs, Rhs rhs) const
{ {
if (rhs == 0) if (rhs == 0)
return AK::Result<Lhs, StringView>("Integer division overflow"sv); return AK::ErrorOr<Lhs, StringView>("Integer division overflow"sv);
if constexpr (IsSigned<Lhs>) { if constexpr (IsSigned<Lhs>) {
if (rhs == -1) if (rhs == -1)
return AK::Result<Lhs, StringView>(0); // Spec weirdness right here, signed division overflow is ignored. return AK::ErrorOr<Lhs, StringView>(0); // Spec weirdness right here, signed division overflow is ignored.
} }
return AK::Result<Lhs, StringView>(lhs % rhs); return AK::ErrorOr<Lhs, StringView>(lhs % rhs);
} }
static StringView name() { return "%"sv; } static StringView name() { return "%"sv; }
@ -479,7 +479,7 @@ struct Floor {
struct Truncate { struct Truncate {
template<typename Lhs> template<typename Lhs>
AK::Result<Lhs, StringView> operator()(Lhs lhs) const AK::ErrorOr<Lhs, StringView> operator()(Lhs lhs) const
{ {
if constexpr (IsSame<Lhs, float>) if constexpr (IsSame<Lhs, float>)
return truncf(lhs); return truncf(lhs);
@ -536,7 +536,7 @@ struct Wrap {
template<typename ResultT> template<typename ResultT>
struct CheckedTruncate { struct CheckedTruncate {
template<typename Lhs> template<typename Lhs>
AK::Result<ResultT, StringView> operator()(Lhs lhs) const AK::ErrorOr<ResultT, StringView> operator()(Lhs lhs) const
{ {
if (isnan(lhs) || isinf(lhs)) // "undefined", let's just trap. if (isnan(lhs) || isinf(lhs)) // "undefined", let's just trap.
return "Truncation undefined behavior"sv; return "Truncation undefined behavior"sv;

View file

@ -28,7 +28,7 @@ static auto parse_vector(Stream& stream)
{ {
ScopeLogger<WASM_BINPARSER_DEBUG> logger; ScopeLogger<WASM_BINPARSER_DEBUG> logger;
if constexpr (requires { T::parse(stream); }) { if constexpr (requires { T::parse(stream); }) {
using ResultT = typename decltype(T::parse(stream))::ValueType; using ResultT = typename decltype(T::parse(stream))::ResultType;
auto count_or_error = stream.read_value<LEB128<size_t>>(); auto count_or_error = stream.read_value<LEB128<size_t>>();
if (count_or_error.is_error()) if (count_or_error.is_error())
return ParseResult<Vector<ResultT>> { with_eof_check(stream, ParseError::ExpectedSize) }; return ParseResult<Vector<ResultT>> { with_eof_check(stream, ParseError::ExpectedSize) };

View file

@ -61,7 +61,7 @@ enum class ParseError {
ByteString parse_error_to_byte_string(ParseError); ByteString parse_error_to_byte_string(ParseError);
template<typename T> template<typename T>
using ParseResult = Result<T, ParseError>; using ParseResult = ErrorOr<T, ParseError>;
AK_TYPEDEF_DISTINCT_ORDERED_ID(size_t, TypeIndex); AK_TYPEDEF_DISTINCT_ORDERED_ID(size_t, TypeIndex);
AK_TYPEDEF_DISTINCT_ORDERED_ID(size_t, FunctionIndex); AK_TYPEDEF_DISTINCT_ORDERED_ID(size_t, FunctionIndex);