#ifdef ghcjs_HOST_OS
#endif
module Language.Javascript.JSaddle.Properties (
objGetPropertyByName
, objGetPropertyAtIndex
, objSetPropertyByName
, objSetPropertyAtIndex
) where
import Language.Javascript.JSaddle.Classes
(ToJSVal(..), ToJSString(..))
import Language.Javascript.JSaddle.Monad (JSM)
import Language.Javascript.JSaddle.Types
(MutableJSArray, Object(..), JSPropertyAttributes,
Index)
#ifdef ghcjs_HOST_OS
import Language.Javascript.JSaddle.Types (JSString)
#else
import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSObjectRef
(jsobjectgetpropertyatindex, jsobjectgetproperty,
jsobjectsetpropertyatindex, jsobjectsetproperty)
import Language.Javascript.JSaddle.Native
(makeNewJSVal, withObject, withJSString, withToJSVal)
#endif
import Control.Monad.Trans.Reader (ask)
import Control.Monad.IO.Class (MonadIO(..))
import Language.Javascript.JSaddle.Value (JSVal)
import Language.Javascript.JSaddle.Arguments ()
import Language.Javascript.JSaddle.String ()
objGetPropertyByName :: ToJSString name
=> Object
-> name
-> MutableJSArray
-> JSM JSVal
#ifdef ghcjs_HOST_OS
objGetPropertyByName this name = liftIO . js_tryGetProp (toJSString name) this
foreign import javascript unsafe "try { $r=$2[$1] } catch(e) { $3[0] = e }"
js_tryGetProp :: JSString -> Object -> MutableJSArray -> IO JSVal
#else
objGetPropertyByName this name exceptions = do
gctxt <- ask
withObject this $ \rthis ->
withJSString (toJSString name) $ \name' ->
(liftIO $ jsobjectgetproperty gctxt rthis name' exceptions) >>= makeNewJSVal
#endif
objGetPropertyAtIndex :: Object
-> Index
-> MutableJSArray
-> JSM JSVal
#ifdef ghcjs_HOST_OS
objGetPropertyAtIndex this index = liftIO . js_tryIndex index this
foreign import javascript unsafe "try { $r=$2[$1] } catch(e) { $3[0] = e }"
js_tryIndex :: Index -> Object -> MutableJSArray -> IO JSVal
#else
objGetPropertyAtIndex this index exceptions = do
gctxt <- ask
withObject this $ \rthis ->
(liftIO $ jsobjectgetpropertyatindex gctxt rthis index exceptions) >>= makeNewJSVal
#endif
objSetPropertyByName :: (ToJSString name, ToJSVal val)
=> Object
-> name
-> val
-> JSPropertyAttributes
-> MutableJSArray
-> JSM ()
#ifdef ghcjs_HOST_OS
objSetPropertyByName this name val attributes exceptions = do
vref <- toJSVal val
liftIO $ js_trySetProp (toJSString name) this vref exceptions
foreign import javascript unsafe "try { $2[$1]=$3 } catch(e) { $4[0] = e }"
js_trySetProp :: JSString -> Object -> JSVal -> MutableJSArray -> IO ()
#else
objSetPropertyByName this name val attributes exceptions = do
gctxt <- ask
withObject this $ \rthis ->
withJSString (toJSString name) $ \name' ->
withToJSVal val $ \rval ->
liftIO $ jsobjectsetproperty gctxt rthis name' rval attributes exceptions
#endif
objSetPropertyAtIndex :: (ToJSVal val)
=> Object
-> Index
-> val
-> MutableJSArray
-> JSM ()
#ifdef ghcjs_HOST_OS
objSetPropertyAtIndex this index val exceptions = do
vref <- toJSVal val
liftIO $ js_trySetAtIndex index this vref exceptions
foreign import javascript unsafe "try { $2[$1]=$3 } catch(e) { $4[0] = e }"
js_trySetAtIndex :: Index -> Object -> JSVal -> MutableJSArray -> IO ()
#else
objSetPropertyAtIndex this index val exceptions = do
gctxt <- ask
withObject this $ \rthis ->
withToJSVal val $ \rval ->
liftIO $ jsobjectsetpropertyatindex gctxt rthis index rval exceptions
#endif