summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/WebAssembly
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-07-22 13:25:57 +0430
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-07-23 17:36:15 +0430
commit7b88857c5ac680528c9d59f7bd2ed0a1d00e8e6d (patch)
treec0cc7357da52372a784d201022175434b6bff9c0 /Userland/Libraries/LibWeb/WebAssembly
parent03629a2b3cc2b39ba434cca2049059cdb3f5f7ed (diff)
downloadserenity-7b88857c5ac680528c9d59f7bd2ed0a1d00e8e6d.zip
LibWeb: Manually convert the js bigint to a wasm i64 value
SignedBigInteger::export() generates sign-magnitude, but the native i64 type uses 2's comp, make this work by exporting it as unsigned and tweaking the sign later.
Diffstat (limited to 'Userland/Libraries/LibWeb/WebAssembly')
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
index 8398c8afab..d3be78d352 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
@@ -374,10 +374,11 @@ Optional<Wasm::Value> to_webassembly_value(JS::Value value, const Wasm::ValueTyp
if (vm.exception())
return {};
auto value = bigint->big_integer().divided_by(two_64).remainder;
- VERIFY(value.trimmed_length() <= 2);
- BigEndian<i64> integer { 0 };
- value.export_data({ &integer, 2 });
- return Wasm::Value { static_cast<i64>(integer) };
+ VERIFY(value.unsigned_value().trimmed_length() <= 2);
+ i64 integer = static_cast<i64>(value.unsigned_value().to_u64());
+ if (value.is_negative())
+ integer = -integer;
+ return Wasm::Value { integer };
}
case Wasm::ValueType::I32: {
auto _i32 = value.to_i32(global_object);