module GHCJS.Prim
( JSVal(..)
, WouldBlockException(..)
, JSException(..)
, mkJSException
, fromJSString
, toJSString
, toJSArray
, fromJSArray
, fromJSInt
, toJSInt
, isNull
, isUndefined
, jsNull
, getProp
, getProp'
) where
import Data.Typeable (Typeable)
import Unsafe.Coerce (unsafeCoerce)
import qualified GHC.Exception as Ex
newtype JSVal = JSVal ()
data JSException = JSException JSVal String
deriving (Typeable)
instance Ex.Exception JSException
instance Show JSException where
show (JSException _ xs) = "JavaScript exception: " ++ xs
mkJSException :: JSVal -> IO JSException
mkJSException ref =
return (JSException (unsafeCoerce ref) (fromJSString ref))
fromJSString :: JSVal -> String
fromJSString = const mempty
toJSString :: String -> JSVal
toJSString = const jsNull
fromJSArray :: JSVal -> IO [JSVal]
fromJSArray = pure mempty
toJSArray :: [JSVal] -> IO JSVal
toJSArray = const $ pure jsNull
fromJSInt :: JSVal -> Int
fromJSInt = const 0
toJSInt :: Int -> JSVal
toJSInt = const jsNull
isNull :: JSVal -> Bool
isNull = const True
isUndefined :: JSVal -> Bool
isUndefined = const True
jsNull :: JSVal
jsNull = JSVal ()
getProp :: JSVal -> String -> IO JSVal
getProp _ _ = pure jsNull
getProp' :: JSVal -> JSVal -> IO JSVal
getProp' _ _ = pure jsNull
data WouldBlockException = WouldBlockException
deriving (Typeable)
instance Show WouldBlockException where
show _ = "thread would block"
instance Ex.Exception WouldBlockException