module GHCJS.Marshal.Pure ( PFromJSVal(..)
, PToJSVal(..)
) where
import Data.Int (Int8, Int16, Int32)
import Data.JSString.Internal.Type
import Data.Text (Text)
import Data.Word (Word8, Word16, Word32, Word)
import Data.JSString as JSS
import Data.JSString.Text
import GHCJS.Types
import qualified GHCJS.Prim as Prim
import GHCJS.Foreign.Internal
import GHCJS.Marshal.Internal
instance PFromJSVal JSVal where pFromJSVal = id
instance PFromJSVal () where pFromJSVal _ = ()
instance PFromJSVal JSString where pFromJSVal _ = JSS.empty
instance PFromJSVal [Char] where pFromJSVal = Prim.fromJSString
instance PFromJSVal Text where pFromJSVal = textFromJSVal
instance PFromJSVal Char where pFromJSVal _ = '?'
instance PFromJSVal Bool where pFromJSVal _ = False
instance PFromJSVal Int where pFromJSVal _ = 0
instance PFromJSVal Int8 where pFromJSVal _ = 0
instance PFromJSVal Int16 where pFromJSVal _ = 0
instance PFromJSVal Int32 where pFromJSVal _ = 0
instance PFromJSVal Word where pFromJSVal _ = 0
instance PFromJSVal Word8 where pFromJSVal _ = 0
instance PFromJSVal Word16 where pFromJSVal _ = 0
instance PFromJSVal Word32 where pFromJSVal _ = 0
instance PFromJSVal Float where pFromJSVal _ = 0
instance PFromJSVal Double where pFromJSVal _ = 0
instance PFromJSVal a => PFromJSVal (Maybe a) where
pFromJSVal x | isUndefined x || isNull x = Nothing
pFromJSVal x = Just (pFromJSVal x)
instance PToJSVal JSVal where pToJSVal = id
instance PToJSVal JSString where pToJSVal = jsval
instance PToJSVal [Char] where pToJSVal = Prim.toJSString
instance PToJSVal Text where pToJSVal = jsval . textToJSString
instance PToJSVal Char where pToJSVal _ = nullRef
instance PToJSVal Bool where pToJSVal True = jsTrue
pToJSVal False = jsFalse
instance PToJSVal Int where pToJSVal _ = nullRef
instance PToJSVal Int8 where pToJSVal _ = nullRef
instance PToJSVal Int16 where pToJSVal _ = nullRef
instance PToJSVal Int32 where pToJSVal _ = nullRef
instance PToJSVal Word where pToJSVal _ = nullRef
instance PToJSVal Word8 where pToJSVal _ = nullRef
instance PToJSVal Word16 where pToJSVal _ = nullRef
instance PToJSVal Word32 where pToJSVal _ = nullRef
instance PToJSVal Float where pToJSVal _ = nullRef
instance PToJSVal Double where pToJSVal _ = nullRef
instance PToJSVal a => PToJSVal (Maybe a) where
pToJSVal Nothing = jsNull
pToJSVal (Just a) = pToJSVal a