summaryrefslogtreecommitdiff
path: root/testsuite/tests/javascript/js-ffi-array.hs
diff options
context:
space:
mode:
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