@@ -401,21 +401,9 @@ foreign import javascript unsafe "console.log($1); $r = JSON['parse']($1);"
402rawDecode :: (FromJSON a) => T.Text -> Maybe a
402rawDecode :: (FromJSON a) => T.Text -> Maybe a
403rawDecode bs = do
403rawDecode bs = do
404− -- Below copied from Reflex.Dom.WebSocket.Foreign
405− -- tmp <- Just $ unsafePerformIO $ putStrLn ("bs: " ++ BS.unpack bs)
406− -- error ("bs: " ++ BS.unpack bs)
407− -- let (b, off, len) = fromByteString bs
408− -- x = return $ js_dataView off len $ jsval $ getArrayBuffer b :: _
409− -- tmp <- error (BS.unpack bs)
411− -- let jsv = if BS.length bs == 0
412− -- then unsafePerformIO $ jsval . getArrayBuffer <$> create 0
413− -- else js_dataView off len $ jsval $ getArrayBuffer b
415 let jsv = T.textToJSString bs
405 let jsv = T.textToJSString bs
418− -- TODO pFromJSVal to avoid unsafePerformIO
419 let res = unsafePerformIO $ try $ aesonFromJSVal $ js_jsonParse $ jsval jsv
407 let res = unsafePerformIO $ try $ aesonFromJSVal $ js_jsonParse $ jsval jsv
420 case res of
408 case res of
421 Left (_e :: SomeException) -> Nothing
409 Left (_e :: SomeException) -> Nothing
@@ -429,8 +417,6 @@ rawDecode bs = do
429-- copied from http://lpaste.net/raw/353535 Thanks ncl28!
417-- copied from http://lpaste.net/raw/353535 Thanks ncl28!
430aesonFromJSVal :: JSVal -> IO (Maybe A.Value)
418aesonFromJSVal :: JSVal -> IO (Maybe A.Value)
431aesonFromJSVal r = do
419aesonFromJSVal r = do
433− print $ jsonTypeOf r
434 case jsonTypeOf r of
420 case jsonTypeOf r of
435 JSONNull -> return (Just A.Null)
421 JSONNull -> return (Just A.Null)
436 JSONInteger -> liftM (A.Number . flip scientific 0 . (toInteger :: Int -> Integer))
422 JSONInteger -> liftM (A.Number . flip scientific 0 . (toInteger :: Int -> Integer))