diff --git a/tests/web/wasm/ffi/ffi_native_test.dart b/tests/web/wasm/ffi/ffi_native_test.dart index 1619f8e28ed..2400828790c 100644 --- a/tests/web/wasm/ffi/ffi_native_test.dart +++ b/tests/web/wasm/ffi/ffi_native_test.dart @@ -5,6 +5,9 @@ // dart2wasmOptions=--extra-compiler-option=--enable-experimental-ffi // SharedObjects=ffi_native_test_module +// Build target `ffi_native_test_wasm_module` for the FFI module used in this +// test. + import 'dart:ffi'; import 'dart:nativewrappers'; @@ -46,8 +49,11 @@ external bool boolReturn(int b); @Native() external void toggleBool(); +@Native() +external double sqrtFloat(double d); + @Native() -external double sqrt(double d); +external double sqrtDouble(double d); @Native() external int incrementChar(int a); @@ -173,6 +179,9 @@ void main() { Expect.equals(incrementUintPtr(25), 26); Expect.equals(incrementSize(27), 28); Expect.equals(incrementWchar(29), 30); + + Expect.equals(sqrtDouble(1e300), 1e150); + Expect.equals(sqrtFloat(1e10), 1e5); } // Don't crash on an unused `Native.addressOf`. diff --git a/tests/web/wasm/ffi/ffi_native_test_module.c b/tests/web/wasm/ffi/ffi_native_test_module.c index 1ba7c8a897d..c64c58ddf6c 100644 --- a/tests/web/wasm/ffi/ffi_native_test_module.c +++ b/tests/web/wasm/ffi/ffi_native_test_module.c @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. #include +#include #include #include #include @@ -163,3 +164,13 @@ EMSCRIPTEN_KEEPALIVE wchar_t incrementWchar(wchar_t a) { return a + 1; } + +EMSCRIPTEN_KEEPALIVE +double sqrtDouble(double d) { + return sqrt(d); +} + +EMSCRIPTEN_KEEPALIVE +float sqrtFloat(float d) { + return sqrtf(d); +} diff --git a/utils/dart2wasm/BUILD.gn b/utils/dart2wasm/BUILD.gn index 6d871989eaf..8c5a2fa5afa 100644 --- a/utils/dart2wasm/BUILD.gn +++ b/utils/dart2wasm/BUILD.gn @@ -19,6 +19,7 @@ template("wasm_module") { rebase_path("$root_out_dir/wasm/${invoker.module_name}.wasm"), "-O", ] + inputs = [ "//tests/web/wasm/ffi/${invoker.module_name}.c" ] outputs = [ "$root_out_dir/wasm/${invoker.module_name}.wasm" ] } }