module JavaScript.Object.Internal
( Object(..)
, create
, listProps
, getProp
, unsafeGetProp
, setProp
, unsafeSetProp
) where
import Language.Javascript.JSaddle.Types (JSM, JSVal, Object(..), JSString)
import Language.Javascript.JSaddle.Native.Internal
(withObject, withJSString, withJSVal, wrapJSString)
import Language.Javascript.JSaddle.Run
(Command(..), AsyncCommand(..), Result(..), sendCommand, sendLazyCommand, sendAsyncCommand)
create :: JSM Object
create = Object <$> sendLazyCommand NewEmptyObject
listProps :: Object -> JSM [JSString]
listProps this =
withObject this $ \rthis -> do
PropertyNamesResult result <- sendCommand $ PropertyNames rthis
mapM wrapJSString result
unsafeGetProp :: JSString -> Object -> JSM JSVal
unsafeGetProp name this =
withObject this $ \rthis ->
withJSString name $ sendLazyCommand . GetPropertyByName rthis
getProp :: JSString -> Object -> JSM JSVal
getProp = unsafeGetProp
unsafeSetProp :: JSString -> JSVal -> Object -> JSM ()
unsafeSetProp name val this =
withObject this $ \rthis ->
withJSString name $ \rname ->
withJSVal val $ \rval ->
sendAsyncCommand $ SetPropertyByName rthis rname rval
setProp :: JSString -> JSVal -> Object -> JSM ()
setProp = unsafeSetProp