1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:57:35 +00:00

LibWasm: Implement reference instructions (ref.{null,func,is_null})

This commit is contained in:
Ali Mohammad Pur 2021-06-01 09:48:36 +04:30 committed by Ali Mohammad Pur
parent 7fb458b7c9
commit 56bf80251c
8 changed files with 73 additions and 9 deletions

View file

@ -190,6 +190,12 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::wasm_invoke)
case Wasm::ValueType::Kind::ExternReference:
arguments.append(Wasm::Value(Wasm::ExternAddress { static_cast<u64>(value) }));
break;
case Wasm::ValueType::Kind::NullFunctionReference:
arguments.append(Wasm::Value(Wasm::Value::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) }));
break;
}
}
@ -206,6 +212,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::wasm_invoke)
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::ExternAddress& index) { return_value = JS::Value(static_cast<double>(index.value())); },
[&](const Wasm::Value::Null&) { return_value = JS::js_null(); });
return return_value;
}