module GHCJS.Prim.Internal ( JSVal(..)
, JSValueRef
, JSException(..)
, WouldBlockException(..)
, mkJSException
, jsNull
) where
import Control.DeepSeq (NFData(..))
import Data.Int (Int64)
import Data.Typeable (Typeable)
import Unsafe.Coerce (unsafeCoerce)
import Data.Aeson (ToJSON(..), FromJSON(..))
import qualified GHC.Exception as Ex
type JSValueRef = Int64
newtype JSVal = JSVal JSValueRef deriving(Show, ToJSON, FromJSON)
instance NFData JSVal where
rnf x = x `seq` ()
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) "")
jsNull :: JSVal
jsNull = JSVal 0
data WouldBlockException = WouldBlockException
deriving (Typeable)
instance Show WouldBlockException where
show _ = "thread would block"
instance Ex.Exception WouldBlockException