on develop help sign in
Add instance FromJS Bool
commitdec40bb8a5dbb4e29a6705cb06e1bbbebdbe1b1b authorRyan Trinkle <ryan.trinkle@gmail.com> dateTue 23 Jun 2015, 01:28 (11 years ago) parent9156be6
1 file changed+8
src/Foreign/JavaScript/TH.hs+8
src/Foreign/JavaScript/TH.hs+8
@@ -70,6 +70,7 @@ class Monad m => MonadJS x m | m -> x where
7070 mkJSUndefined :: m (JSRef x)
7171 isJSNull :: JSRef x -> m Bool
7272 isJSUndefined :: JSRef x -> m Bool
73+ fromJSBool :: JSRef x -> m Bool
7374 fromJSString :: JSRef x -> m String
7475 fromJSArray :: JSRef x -> m [JSRef x]
7576 fromJSNumber :: JSRef x -> m Double
@@ -96,6 +97,7 @@ instance MonadJS JSCtx_IO IO where
9697 mkJSUndefined = return $ JSRef_IO JS.jsUndefined
9798 isJSNull (JSRef_IO r) = return $ JS.isNull r
9899 isJSUndefined (JSRef_IO r) = return $ JS.isUndefined r
100+ fromJSBool (JSRef_IO r) = return $ JS.fromJSBool $ JS.castRef r
99101 fromJSString (JSRef_IO r) = return $ JS.fromJSString $ JS.castRef r
100102 fromJSArray (JSRef_IO r) = liftM coerce $ JS.fromArray $ JS.castRef r
101103 fromJSNumber (JSRef_IO r) = do
@@ -174,6 +176,9 @@ instance MonadJS (JSCtx_JavaScriptCore x) (WithWebView x IO) where
174176 isJSUndefined (JSRef_JavaScriptCore r) = do
175177 jsContext <- askJSContext
176178 liftIO $ jsvalueisundefined jsContext r
179+ fromJSBool (JSRef_JavaScriptCore r) = do
180+ jsContext <- askJSContext
181+ liftIO $ jsvaluetoboolean jsContext r
177182 fromJSString (JSRef_JavaScriptCore r) = do
178183 jsContext <- askJSContext
179184 liftIO $ do
@@ -258,6 +263,9 @@ class FromJS x a where
258263instance FromJS x () where
259264 fromJS _ = return () --TODO: Should this do some kind of checking for the js value?
260265
266+instance FromJS x Bool where
267+ fromJS = fromJSBool
268+
261269instance FromJS x String where
262270 fromJS = fromJSString
263271