Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions jsaddle/src-ghc/GHCJS/Marshal/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,22 @@ class ToJSVal a where
default toJSVal :: (Generic a, GToJSVal (Rep a ())) => a -> JSM JSVal
toJSVal = toJSVal_generic id

instance ToJSVal (SomeJSArray Immutable) where
toJSVal (SomeJSArray x) = pure x

fromJustWithStack :: JSadddleHasCallStack => Maybe a -> a
fromJustWithStack Nothing = error "fromJSValUnchecked: fromJSVal result was Nothing"
fromJustWithStack (Just x) = x

class FromJSVal a where
fromJSVal :: JSVal -> JSM (Maybe a)

instance FromJSVal Function where
fromJSVal = pure . pure . Function . Object

instance FromJSVal Object where
fromJSVal = pure . pure . Object

#if MIN_VERSION_base(4,9,0) && defined(JSADDLE_HAS_CALL_STACK)
fromJSValUnchecked :: JSadddleHasCallStack => JSVal -> JSM a
#ifdef CHECK_UNCHECKED
Expand Down
13 changes: 12 additions & 1 deletion jsaddle/src/Language/Javascript/JSaddle/Classes/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Language.Javascript.JSaddle.Classes.Internal (
) where

import Language.Javascript.JSaddle.Types
(JSM, Object(..), JSVal)
(JSM, Object(..), JSVal, JSString(..), Function(..), Object(..))

-- | Anything that can be used to make a JavaScript object reference
class MakeObject this where
Expand All @@ -39,3 +39,14 @@ class MakeArgs this where
instance MakeArgs arg => MakeArgs (JSM arg) where
makeArgs arg = arg >>= makeArgs

instance MakeArgs Int where
makeArgs arg = (:[]) <$> toJSVal arg

instance MakeArgs Object where
makeArgs (Object arg) = pure [arg]

instance MakeArgs JSString where
makeArgs (JSString arg) = makeArgs arg

instance MakeArgs Function where
makeArgs (Function (Object arg)) = pure [arg]