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
import Data.IORef (newIORef, IORef)
import System.IO.Unsafe (unsafePerformIO)
type JSValueRef = Int64
newtype JSVal = JSVal (IORef JSValueRef)
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 . unsafePerformIO $ newIORef 0
data WouldBlockException = WouldBlockException
deriving (Typeable)
instance Show WouldBlockException where
show _ = "thread would block"
instance Ex.Exception WouldBlockException