module GHCJS.Foreign.Internal (
jsTrue
, jsFalse
, jsNull
, toJSBool
, jsUndefined
, isTruthy
, isNull
, isUndefined
, JSType(..)
) where
import Language.Javascript.JSaddle.Types (JSVal(..), GHCJSPure(..))
import Language.Javascript.JSaddle.Native.Internal
(valueToBool)
import Data.Typeable (Typeable)
import GHCJS.Prim (isNull, isUndefined)
import System.IO.Unsafe (unsafePerformIO)
import Data.IORef (newIORef)
jsTrue :: JSVal
jsTrue = JSVal . unsafePerformIO $ newIORef 3
jsFalse :: JSVal
jsFalse = JSVal . unsafePerformIO $ newIORef 2
jsNull :: JSVal
jsNull = JSVal . unsafePerformIO $ newIORef 0
toJSBool :: Bool -> JSVal
toJSBool b = JSVal . unsafePerformIO . newIORef $ if b then 3 else 2
jsUndefined :: JSVal
jsUndefined = JSVal . unsafePerformIO $ newIORef 1
isTruthy :: JSVal -> GHCJSPure Bool
isTruthy = GHCJSPure . valueToBool
data JSType = Undefined
| Object
| Boolean
| Number
| String
| Symbol
| Function
| Other
deriving (Show, Eq, Ord, Enum, Typeable)