summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-06-04 03:30:09 +0430
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-06-04 16:07:42 +0430
commitbe62e4d1d7a8c5e58f864dd893dc6042c96e330f (patch)
tree18cbce06e57687a089e38565027dfecd794ccf35 /Tests
parentc392a0cf7ffbad07c10021b9a3e97f5239b40c55 (diff)
downloadserenity-be62e4d1d7a8c5e58f864dd893dc6042c96e330f.zip
LibWasm: Load and instantiate tables
This commit is a fairly large refactor, mainly because it unified the two different ways that existed to represent references. Now Reference values are also a kind of value. It also implements a printer for values/references instead of copying the implementation everywhere.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/LibWasm/test-wasm.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp
index d1143bf1c6..086203251b 100644
--- a/Tests/LibWasm/test-wasm.cpp
+++ b/Tests/LibWasm/test-wasm.cpp
@@ -185,16 +185,16 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::wasm_invoke)
arguments.append(Wasm::Value(static_cast<double>(value)));
break;
case Wasm::ValueType::Kind::FunctionReference:
- arguments.append(Wasm::Value(Wasm::FunctionAddress { static_cast<u64>(value) }));
+ arguments.append(Wasm::Value(Wasm::Reference { Wasm::Reference::Func { static_cast<u64>(value) } }));
break;
case Wasm::ValueType::Kind::ExternReference:
- arguments.append(Wasm::Value(Wasm::ExternAddress { static_cast<u64>(value) }));
+ arguments.append(Wasm::Value(Wasm::Reference { Wasm::Reference::Func { static_cast<u64>(value) } }));
break;
case Wasm::ValueType::Kind::NullFunctionReference:
- arguments.append(Wasm::Value(Wasm::Value::Null { Wasm::ValueType(Wasm::ValueType::Kind::FunctionReference) }));
+ arguments.append(Wasm::Value(Wasm::Reference { Wasm::Reference::Null { Wasm::ValueType(Wasm::ValueType::Kind::FunctionReference) } }));
break;
case Wasm::ValueType::Kind::NullExternReference:
- arguments.append(Wasm::Value(Wasm::Value::Null { Wasm::ValueType(Wasm::ValueType::Kind::ExternReference) }));
+ arguments.append(Wasm::Value(Wasm::Reference { Wasm::Reference::Null { Wasm::ValueType(Wasm::ValueType::Kind::ExternReference) } }));
break;
}
}
@@ -211,8 +211,10 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::wasm_invoke)
JS::Value return_value;
result.values().first().value().visit(
[&](const auto& value) { return_value = JS::Value(static_cast<double>(value)); },
- [&](const Wasm::FunctionAddress& index) { return_value = JS::Value(static_cast<double>(index.value())); },
- [&](const Wasm::ExternAddress& index) { return_value = JS::Value(static_cast<double>(index.value())); },
- [&](const Wasm::Value::Null&) { return_value = JS::js_null(); });
+ [&](const Wasm::Reference& 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;
}