mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 21:59:07 +00:00
LibWasm: Preserve sign bit across JS boundary in test-wasm
A `Uint8Array` can now be passed in the Wasm testjs files to be transmuted into a Wasm value.
This commit is contained in:
parent
63a5ff70e5
commit
6493acf2f4
Notes:
sideshowbarker
2024-07-17 07:08:37 +09:00
Author: https://github.com/dzfrias
Commit: 6493acf2f4
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/459
Reviewed-by: https://github.com/alimpfard
2 changed files with 22 additions and 8 deletions
|
@ -256,7 +256,17 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::wasm_invoke)
|
|||
for (auto& param : type->parameters()) {
|
||||
auto argument = vm.argument(index++);
|
||||
double double_value = 0;
|
||||
if (!argument.is_bigint())
|
||||
if (argument.is_object()) {
|
||||
auto object = MUST(argument.to_object(vm));
|
||||
// Uint8Array allows for raw bytes to be passed into Wasm. This is
|
||||
// particularly useful for preserving the sign bit of a NaN
|
||||
if (!is<JS::Uint8Array>(*object))
|
||||
return vm.throw_completion<JS::TypeError>("Expected a Uint8Array object"sv);
|
||||
auto& array = static_cast<JS::Uint8Array&>(*object);
|
||||
if (array.array_length().length() != 8)
|
||||
return vm.throw_completion<JS::TypeError>("Expected a Uint8Array of size 8"sv);
|
||||
memcpy(&double_value, array.data().data(), sizeof(double));
|
||||
} else if (!argument.is_bigint())
|
||||
double_value = TRY(argument.to_double(vm));
|
||||
switch (param.kind()) {
|
||||
case Wasm::ValueType::Kind::I32:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue