From 75150152f51b21db78bd3cef70b47a5ec98a4c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 28 Jun 2026 13:26:33 +0200 Subject: Newtype wrappers for some JavaScript values --- src/JavaScript/Val.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/JavaScript/Val.hs (limited to 'src/JavaScript/Val.hs') diff --git a/src/JavaScript/Val.hs b/src/JavaScript/Val.hs new file mode 100644 index 0000000..e1879b4 --- /dev/null +++ b/src/JavaScript/Val.hs @@ -0,0 +1,24 @@ +module JavaScript.Val ( + module GHC.Wasm.Prim, + ToJSVal(..), FromJSVal(..), + nullToNothing, +) where + +import GHC.Wasm.Prim + + +class ToJSVal a where + toJSVal :: a -> JSVal + +class FromJSVal a where + fromJSValUnchecked :: JSVal -> a + +instance ToJSVal JSVal where toJSVal = id +instance FromJSVal JSVal where fromJSValUnchecked = id + + +nullToNothing :: FromJSVal a => JSVal -> Maybe a +nullToNothing val | isNull val = Nothing + | otherwise = Just $ fromJSValUnchecked val +foreign import javascript unsafe "$1 === null" + isNull :: JSVal -> Bool -- cgit v1.2.3