From b7dce5cdd564d8cf1e60f90b33e0218912d691f9 Mon Sep 17 00:00:00 2001
From: Cheng Shao <terrorjack@type.dance>
Date: Fri, 21 Feb 2025 00:37:20 +0000
Subject: [PATCH] testsuite: test wasm backend JSFFI sync exports

This commit repurposes some existing JSFFI test cases to make them
cover JSFFI sync exports as well.

(cherry picked from commit b6ae908bd3ae7b75b79925e56c3e11ba5c40b5ec)
---
 testsuite/tests/jsffi/jsffigc.hs   | 7 +++----
 testsuite/tests/jsffi/jsffigc.mjs  | 2 +-
 testsuite/tests/jsffi/textconv.hs  | 2 +-
 testsuite/tests/jsffi/textconv.mjs | 4 ++--
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/testsuite/tests/jsffi/jsffigc.hs b/testsuite/tests/jsffi/jsffigc.hs
index 7b0f89798ae..1ad8ebe6ed9 100644
--- a/testsuite/tests/jsffi/jsffigc.hs
+++ b/testsuite/tests/jsffi/jsffigc.hs
@@ -10,17 +10,16 @@ import System.Mem
 
 type BinOp a = a -> a -> a
 
-foreign import javascript "wrapper"
+foreign import javascript "wrapper sync"
   js_from_hs :: BinOp Int -> IO JSVal
 
--- This must be safe since we intend to call back into Haskell again.
-foreign import javascript safe "dynamic"
+foreign import javascript unsafe "dynamic"
   js_to_hs :: JSVal -> BinOp Int
 
 foreign import javascript "wrapper"
   js_mk_cont :: IO () -> IO JSVal
 
-foreign export javascript "testDynExportFree"
+foreign export javascript "testDynExportFree sync"
   testDynExportFree :: Int -> Int -> Int -> IO ()
 
 -- JSVal uses Weak# under the hood for garbage collection support,
diff --git a/testsuite/tests/jsffi/jsffigc.mjs b/testsuite/tests/jsffi/jsffigc.mjs
index 3178a8a83a0..50401200e10 100644
--- a/testsuite/tests/jsffi/jsffigc.mjs
+++ b/testsuite/tests/jsffi/jsffigc.mjs
@@ -8,7 +8,7 @@ async function reallyGC() {
 }
 
 export default async (__exports) => {
-  await __exports.testDynExportFree(114, 514, 1919810);
+  __exports.testDynExportFree(114, 514, 1919810);
 
   const cont = await __exports.testDynExportGC(114, 514, 1919810);
   await reallyGC();
diff --git a/testsuite/tests/jsffi/textconv.hs b/testsuite/tests/jsffi/textconv.hs
index d7ca3581cc3..a504f13a794 100644
--- a/testsuite/tests/jsffi/textconv.hs
+++ b/testsuite/tests/jsffi/textconv.hs
@@ -45,7 +45,7 @@ textToJSString (Text (ByteArray ba#) (I# off#) (I# len#)) = unsafeDupablePerform
     (# s1, mba# #) -> case copyByteArray# ba# off# mba# 0# len# s1 of
       s2 -> keepAlive# mba# s2 $ unIO $ js_to_str (Ptr (mutableByteArrayContents# mba#)) $ I# len#
 
-foreign export javascript "main"
+foreign export javascript "main sync"
   main :: IO ()
 
 main :: IO ()
diff --git a/testsuite/tests/jsffi/textconv.mjs b/testsuite/tests/jsffi/textconv.mjs
index 56ef3fdeef4..2319e7e1bcc 100644
--- a/testsuite/tests/jsffi/textconv.mjs
+++ b/testsuite/tests/jsffi/textconv.mjs
@@ -1,3 +1,3 @@
-export default async (__exports) => {
-  await __exports.main();
+export default (__exports) => {
+  __exports.main();
 }
-- 
GitLab