mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
LibWasm: Allow all Value::to<Integral>() calls
This brings back the old behaviour of Value::to<short>() (and other similar calls), which WASI depends on. To make sure all similar issues are caught in the future, this commit also introduces an static assertion in Value::to(). (cherry picked from commit 0d05ab2ad0cc56cc6fe9ee647dfcfda44a92b4f2)
This commit is contained in:
parent
584e555f33
commit
28af9da66f
1 changed files with 6 additions and 12 deletions
|
@ -142,22 +142,16 @@ public:
|
|||
template<typename T>
|
||||
ALWAYS_INLINE T to() const
|
||||
{
|
||||
static_assert(IsOneOf<T, u128, u64, i64, f32, f64, Reference> || IsIntegral<T>, "Unsupported type for Value::to()");
|
||||
|
||||
if constexpr (IsSame<T, u128>) {
|
||||
return m_value;
|
||||
}
|
||||
if constexpr (IsSame<T, u32>) {
|
||||
u32 low = m_value.low() & 0xFFFFFFFF;
|
||||
return low;
|
||||
if constexpr (IsOneOf<T, u64, i64>) {
|
||||
return bit_cast<T>(m_value.low());
|
||||
}
|
||||
if constexpr (IsSame<T, i32>) {
|
||||
u32 low = m_value.low() & 0xFFFFFFFF;
|
||||
return bit_cast<i32>(low);
|
||||
}
|
||||
if constexpr (IsSame<T, u64>) {
|
||||
return bit_cast<u64>(m_value.low());
|
||||
}
|
||||
if constexpr (IsSame<T, i64>) {
|
||||
return bit_cast<i64>(m_value.low());
|
||||
if constexpr (IsIntegral<T> && sizeof(T) < 8) {
|
||||
return bit_cast<T>(static_cast<MakeUnsigned<T>>(m_value.low() & NumericLimits<MakeUnsigned<T>>::max()));
|
||||
}
|
||||
if constexpr (IsSame<T, f32>) {
|
||||
u32 low = m_value.low() & 0xFFFFFFFF;
|
||||
|
|
Loading…
Add table
Reference in a new issue