mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Tests: Implement multi-value returns in test-wasm
This commit is contained in:
parent
8a36d8826f
commit
5bc1f135b7
Notes:
sideshowbarker
2024-07-17 07:48:42 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/5bc1f135b7 Pull-request: https://github.com/SerenityOS/serenity/pull/17612 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/linusg
1 changed files with 18 additions and 11 deletions
|
@ -252,15 +252,22 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::wasm_invoke)
|
|||
if (result.values().is_empty())
|
||||
return JS::js_null();
|
||||
|
||||
JS::Value return_value;
|
||||
result.values().first().value().visit(
|
||||
[&](auto const& value) { return_value = JS::Value(static_cast<double>(value)); },
|
||||
[&](i32 value) { return_value = JS::Value(static_cast<double>(value)); },
|
||||
[&](i64 value) { return_value = JS::Value(JS::BigInt::create(vm, Crypto::SignedBigInteger { value })); },
|
||||
[&](Wasm::Reference const& reference) {
|
||||
reference.ref().visit(
|
||||
[&](const Wasm::Reference::Null&) { return_value = JS::js_null(); },
|
||||
[&](const auto& ref) { return_value = JS::Value(static_cast<double>(ref.address.value())); });
|
||||
});
|
||||
return return_value;
|
||||
auto to_js_value = [&](Wasm::Value const& value) {
|
||||
return value.value().visit(
|
||||
[](auto const& value) { return JS::Value(static_cast<double>(value)); },
|
||||
[](i32 value) { return JS::Value(static_cast<double>(value)); },
|
||||
[&](i64 value) { return JS::Value(JS::BigInt::create(vm, Crypto::SignedBigInteger { value })); },
|
||||
[](Wasm::Reference const& reference) {
|
||||
return reference.ref().visit(
|
||||
[](const Wasm::Reference::Null&) { return JS::js_null(); },
|
||||
[](const auto& ref) { return JS::Value(static_cast<double>(ref.address.value())); });
|
||||
});
|
||||
};
|
||||
|
||||
if (result.values().size() == 1)
|
||||
return to_js_value(result.values().first());
|
||||
|
||||
return JS::Array::create_from<Wasm::Value>(*vm.current_realm(), result.values(), [&](Wasm::Value value) {
|
||||
return to_js_value(value);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue