{-# LANGUAGE ForeignFunctionInterface, JavaScriptFFI, UnliftedFFITypes,
GHCForeignImportPrim, DeriveDataTypeable, GHCForeignImportPrim #-}
module GHCJS.Foreign.Callback
( Callback
, OnBlocked(..)
, releaseCallback
, asyncCallback
, asyncCallback1
, asyncCallback2
, asyncCallback3
, syncCallback
, syncCallback1
, syncCallback2
, syncCallback3
, syncCallback'
, syncCallback1'
, syncCallback2'
, syncCallback3'
) where
import GHCJS.Concurrent
import GHCJS.Marshal
import GHCJS.Marshal.Pure
import GHCJS.Foreign.Callback.Internal
import GHCJS.Prim
import GHCJS.Types
import qualified GHC.Exts as Exts
import Data.Typeable
import Unsafe.Coerce
releaseCallback :: Callback a -> IO ()
releaseCallback x = js_release x
syncCallback :: OnBlocked
-> IO ()
-> IO (Callback (IO ()))
syncCallback onBlocked x = js_syncCallback (onBlocked == ContinueAsync) (unsafeCoerce x)
syncCallback1 :: OnBlocked
-> (JSVal -> IO ())
-> IO (Callback (JSVal -> IO ()))
syncCallback1 onBlocked x = js_syncCallbackApply (onBlocked == ContinueAsync) 1 (unsafeCoerce x)
syncCallback2 :: OnBlocked
-> (JSVal -> JSVal -> IO ())
-> IO (Callback (JSVal -> JSVal -> IO ()))
syncCallback2 onBlocked x = js_syncCallbackApply (onBlocked == ContinueAsync) 2 (unsafeCoerce x)
syncCallback3 :: OnBlocked
-> (JSVal -> JSVal -> JSVal -> IO ())
-> IO (Callback (JSVal -> JSVal -> JSVal -> IO ()))
syncCallback3 onBlocked x = js_syncCallbackApply (onBlocked == ContinueAsync) 3 (unsafeCoerce x)
syncCallback' :: IO JSVal
-> IO (Callback (IO JSVal))
syncCallback' x = js_syncCallbackReturn (unsafeCoerce x)
syncCallback1' :: (JSVal -> IO JSVal)
-> IO (Callback (JSVal -> IO JSVal))
syncCallback1' x = js_syncCallbackApplyReturn 1 (unsafeCoerce x)
syncCallback2' :: (JSVal -> JSVal -> IO JSVal)
-> IO (Callback (JSVal -> JSVal -> IO JSVal))
syncCallback2' x = js_syncCallbackApplyReturn 2 (unsafeCoerce x)
syncCallback3' :: (JSVal -> JSVal -> JSVal -> IO JSVal)
-> IO (Callback (JSVal -> JSVal -> JSVal -> IO JSVal))
syncCallback3' x = js_syncCallbackApplyReturn 3 (unsafeCoerce x)
asyncCallback :: IO ()
-> IO (Callback (IO ()))
asyncCallback x = js_asyncCallback (unsafeCoerce x)
asyncCallback1 :: (JSVal -> IO ())
-> IO (Callback (JSVal -> IO ()))
asyncCallback1 x = js_asyncCallbackApply 1 (unsafeCoerce x)
asyncCallback2 :: (JSVal -> JSVal -> IO ())
-> IO (Callback (JSVal -> JSVal -> IO ()))
asyncCallback2 x = js_asyncCallbackApply 2 (unsafeCoerce x)
asyncCallback3 :: (JSVal -> JSVal -> JSVal -> IO ())
-> IO (Callback (JSVal -> JSVal -> JSVal -> IO ()))
asyncCallback3 x = js_asyncCallbackApply 3 (unsafeCoerce x)
foreign import javascript unsafe "h$makeCallback(h$runSync, [$1], $2)"
js_syncCallback :: Bool -> Exts.Any -> IO (Callback (IO b))
foreign import javascript unsafe "h$makeCallback(h$run, [], $1)"
js_asyncCallback :: Exts.Any -> IO (Callback (IO b))
foreign import javascript unsafe "h$makeCallback(h$runSyncReturn, [false], $1)"
js_syncCallbackReturn :: Exts.Any -> IO (Callback (IO JSVal))
foreign import javascript unsafe "h$makeCallbackApply($2, h$runSync, [$1], $3)"
js_syncCallbackApply :: Bool -> Int -> Exts.Any -> IO (Callback b)
foreign import javascript unsafe "h$makeCallbackApply($1, h$run, [], $2)"
js_asyncCallbackApply :: Int -> Exts.Any -> IO (Callback b)
foreign import javascript unsafe
"h$makeCallbackApply($1, h$runSyncReturn, [false], $2)"
js_syncCallbackApplyReturn :: Int -> Exts.Any -> IO (Callback b)
foreign import javascript unsafe "h$release"
js_release :: Callback a -> IO ()