summaryrefslogtreecommitdiff
path: root/testsuite/tests/javascript/js-ffi-array.hs
diff options
context:
space:
mode:
authorJosh Meredith <joshmeredith2008@gmail.com>2023-03-06 09:18:03 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-04-13 08:51:09 -0400
commit27d2978e5412f2bef4448e208182a03137dd5ee8 (patch)
tree0e98a70f487c9c06061d92338de6fd9da593d3f6 /testsuite/tests/javascript/js-ffi-array.hs
parent8af401ccfbe28d7bbfc493c0097834e9c66a36b0 (diff)
downloadhaskell-27d2978e5412f2bef4448e208182a03137dd5ee8.tar.gz
Base/JS: GHC.JS.Foreign.Callback module (issue 23126)
* Add the Callback module for "exporting" Haskell functions to be available to plain JavaScript code * Fix some primitives defined in GHC.JS.Prim * Add a JavaScript section to the user guide with instructions on how to use the JavaScript FFI, building up to using Callbacks to interact with the browser * Add tests for the JavaScript FFI and Callbacks
Diffstat (limited to 'testsuite/tests/javascript/js-ffi-array.hs')
-rw-r--r--testsuite/tests/javascript/js-ffi-array.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/testsuite/tests/javascript/js-ffi-array.hs b/testsuite/tests/javascript/js-ffi-array.hs
new file mode 100644
index 0000000000..00e1e80383
--- /dev/null
+++ b/testsuite/tests/javascript/js-ffi-array.hs
@@ -0,0 +1,18 @@
+import GHC.JS.Prim
+
+foreign import javascript "((xs) => { console.log(xs) })"
+ log_js :: JSVal -> IO ()
+
+foreign import javascript "((xs,i) => { return xs[i]; })"
+ js_index :: JSVal -> JSVal -> JSVal
+
+foreign import javascript "(() => { return ['t','e','s','t']; })"
+ an_array :: JSVal
+
+main :: IO ()
+main = do
+ log_js =<< toJSArray []
+ log_js =<< toJSArray [jsNull, toJSInt 0, toJSString "", toJSInt 1, toJSString "test", toJSInt 2]
+ xs <- toJSArray $ map toJSInt [1..10]
+ log_js $ js_index xs (toJSInt 3)
+ mapM_ log_js =<< fromJSArray an_array