From 99199b9bfdd40a94146bd43014ded6d9b14fca62 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Mon, 30 Aug 2021 16:19:22 +0430 Subject: Tests/LibWasm: Add support for javascript bigint values Some i64 values will not fit in normal doubles, and these values _are_ tested by the test suite, this makes the test runtime capable of handling them correctly. --- Tests/LibWasm/test-wasm.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'Tests') diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp index 4fe48f67e9..838790bdd3 100644 --- a/Tests/LibWasm/test-wasm.cpp +++ b/Tests/LibWasm/test-wasm.cpp @@ -184,6 +184,8 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::get_export) if (auto v = value.get_pointer()) { return m_machine.store().get(*v)->value().value().visit( [&](const auto& value) -> JS::Value { return JS::Value(static_cast(value)); }, + [&](i32 value) { return JS::Value(static_cast(value)); }, + [&](i64 value) -> JS::Value { return JS::js_bigint(vm, Crypto::SignedBigInteger::create_from(value)); }, [&](const Wasm::Reference& reference) -> JS::Value { return reference.ref().visit( [&](const Wasm::Reference::Null&) -> JS::Value { return JS::js_null(); }, @@ -224,25 +226,33 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::wasm_invoke) } size_t index = 1; for (auto& param : type->parameters()) { - auto value = vm.argument(index++).to_double(global_object); + auto argument = vm.argument(index++); + double double_value = 0; + if (!argument.is_bigint()) + double_value = argument.to_double(global_object); switch (param.kind()) { case Wasm::ValueType::Kind::I32: - arguments.append(Wasm::Value(param, static_cast(value))); + arguments.append(Wasm::Value(param, static_cast(double_value))); break; case Wasm::ValueType::Kind::I64: - arguments.append(Wasm::Value(param, static_cast(value))); + if (argument.is_bigint()) { + auto value = argument.to_bigint_int64(global_object); + arguments.append(Wasm::Value(param, bit_cast(value))); + } else { + arguments.append(Wasm::Value(param, static_cast(double_value))); + } break; case Wasm::ValueType::Kind::F32: - arguments.append(Wasm::Value(static_cast(value))); + arguments.append(Wasm::Value(static_cast(double_value))); break; case Wasm::ValueType::Kind::F64: - arguments.append(Wasm::Value(static_cast(value))); + arguments.append(Wasm::Value(static_cast(double_value))); break; case Wasm::ValueType::Kind::FunctionReference: - arguments.append(Wasm::Value(Wasm::Reference { Wasm::Reference::Func { static_cast(value) } })); + arguments.append(Wasm::Value(Wasm::Reference { Wasm::Reference::Func { static_cast(double_value) } })); break; case Wasm::ValueType::Kind::ExternReference: - arguments.append(Wasm::Value(Wasm::Reference { Wasm::Reference::Func { static_cast(value) } })); + arguments.append(Wasm::Value(Wasm::Reference { Wasm::Reference::Func { static_cast(double_value) } })); break; case Wasm::ValueType::Kind::NullFunctionReference: arguments.append(Wasm::Value(Wasm::Reference { Wasm::Reference::Null { Wasm::ValueType(Wasm::ValueType::Kind::FunctionReference) } })); @@ -265,6 +275,8 @@ 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(value)); }, + [&](i32 value) { return_value = JS::Value(static_cast(value)); }, + [&](i64 value) { return_value = JS::Value(JS::js_bigint(vm, Crypto::SignedBigInteger::create_from(value))); }, [&](const Wasm::Reference& reference) { reference.ref().visit( [&](const Wasm::Reference::Null&) { return_value = JS::js_null(); }, -- cgit v1.2.3