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
{-# INLINE fromJSString #-}
toJSString :: String -> JSVal
toJSString = const jsNull
{-# INLINE toJSString #-}
fromJSArray :: JSVal -> IO [JSVal]
fromJSArray = pure mempty
{-# INLINE fromJSArray #-}
toJSArray :: [JSVal] -> IO JSVal
toJSArray = const $ pure jsNull
{-# INLINE toJSArray #-}
fromJSInt :: JSVal -> Int
fromJSInt = const 0
{-# INLINE fromJSInt #-}
toJSInt :: Int -> JSVal
toJSInt = const jsNull
{-# INLINE toJSInt #-}
isNull :: JSVal -> Bool
isNull = const True
{-# INLINE isNull #-}
isUndefined :: JSVal -> Bool
isUndefined = const True
{-# INLINE isUndefined #-}
jsNull :: JSVal
jsNull = JSVal ()
{-# INLINE jsNull #-}
getProp :: JSVal -> String -> IO JSVal
getProp _ _ = pure jsNull
{-# INLINE getProp #-}
getProp' :: JSVal -> JSVal -> IO JSVal
getProp' _ _ = pure jsNull
{-# INLINE getProp' #-}
data WouldBlockException = WouldBlockException
deriving (Typeable)
instance Show WouldBlockException where
show _ = "thread would block"
instance Ex.Exception WouldBlockException