mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-11 18:50:50 +00: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().
This commit is contained in:
parent
e3b3041a0c
commit
0d05ab2ad0
Notes:
github-actions[bot]
2024-08-16 19:04:01 +00:00
Author: https://github.com/alimpfard
Commit: 0d05ab2ad0
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1089
1 changed files with 6 additions and 12 deletions
|
@ -142,22 +142,16 @@ public:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ALWAYS_INLINE T to() const
|
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>) {
|
if constexpr (IsSame<T, u128>) {
|
||||||
return m_value;
|
return m_value;
|
||||||
}
|
}
|
||||||
if constexpr (IsSame<T, u32>) {
|
if constexpr (IsOneOf<T, u64, i64>) {
|
||||||
u32 low = m_value.low() & 0xFFFFFFFF;
|
return bit_cast<T>(m_value.low());
|
||||||
return low;
|
|
||||||
}
|
}
|
||||||
if constexpr (IsSame<T, i32>) {
|
if constexpr (IsIntegral<T> && sizeof(T) < 8) {
|
||||||
u32 low = m_value.low() & 0xFFFFFFFF;
|
return bit_cast<T>(static_cast<MakeUnsigned<T>>(m_value.low() & NumericLimits<MakeUnsigned<T>>::max()));
|
||||||
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 (IsSame<T, f32>) {
|
if constexpr (IsSame<T, f32>) {
|
||||||
u32 low = m_value.low() & 0xFFFFFFFF;
|
u32 low = m_value.low() & 0xFFFFFFFF;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue