Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FromJSVal Aeson instance broken w.r.t. objects. #88

Closed
FPtje opened this issue Mar 5, 2017 · 1 comment
Closed

FromJSVal Aeson instance broken w.r.t. objects. #88

FPtje opened this issue Mar 5, 2017 · 1 comment

Comments

@FPtje
Copy link

FPtje commented Mar 5, 2017

Program to reproduce

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PackageImports #-}

module Main where

import qualified "aeson" Data.Aeson as AE
import           "ghcjs-base" GHCJS.Types ( jsval )
import           "ghcjs-base" GHCJS.Marshal ( fromJSValUnchecked )
import           "ghcjs-base" GHCJS.Foreign ( jsTrue )
import qualified "ghcjs-base" JavaScript.Object as Obj


main :: IO ()
main = do
  putStrLn "Creating object"
  obj <- Obj.create

  Obj.setProp "foo" jsTrue obj

  putStrLn "Object -> JSVal"
  let jsv = jsval obj

  putStrLn "Going to Aeson"
  x <- (fromJSValUnchecked jsv) :: IO AE.Value -- <-- Error here

  putStrLn $ seq x "Evaluated x"

Output

Creating object

lib.js:4616 Object -> JSVal

lib.js:4616 Going to Aeson

rts.js:7062 uncaught exception in Haskell main thread: TypeError: Cannot read property 't' of undefined
rts.js:7062 TypeError: Cannot read property 't' of undefined
    at h$e (rts.js:18673)
    at h$$Bz (out.js:28148)
    at h$runThreadSlice (rts.js:8012)
    at h$runThreadSliceCatch (rts.js:7968)
    at h$mainLoop (rts.js:7963)
    at rts.js:2460
    at runIfPresent (rts.js:2478)
    at onGlobalMessage (rts.js:2512)
rts.js:8313 Uncaught h$ThreadAbortedError {code: 0}
h$exitProcess @ rts.js:8313
h$doneMain @ rts.js:8298
h$doneMain_e @ rts.js:12230
h$runThreadSliceCatch @ rts.js:7975
h$mainLoop @ rts.js:7963
(anonymous) @ rts.js:2460
runIfPresent @ rts.js:2478
onGlobalMessage @ rts.js:2512

ghcjs version:
The Glorious Glasgow Haskell Compilation System for JavaScript, version 0.2.1 (GHC 8.0.2)
ghcjs-0.2.020161101

Package versions:

    aeson-0.11.2.0
    array-0.5.1.1
    attoparsec-0.13.0.2
    base-4.9.0.0
    binary-0.8.3.0
    bytestring-0.10.8.1
    containers-0.5.7.1
    deepseq-1.4.2.0
    directory-1.2.6.2
    dlist-0.7.1.2
    fail-4.9.0.0
    filepath-1.4.1.0
    ghc-8.0.1
    ghc-boot-8.0.1
    ghc-boot-th-8.0.1
    ghc-prim-0.5.0.0
    ghci-8.0.1
    ghcjs-base-0.2.0.0
    ghcjs-dom-0.7.0.4
    ghcjs-dom-jsffi-0.7.0.4
    ghcjs-ffiqq-0.1.0.0
    ghcjs-prim-0.1.0.0
    ghcjs-th-0.1.0.0
    hashable-1.2.4.0
    integer-gmp-1.0.0.1
    mtl-2.2.2
    pretty-1.1.3.3
    primitive-0.6.1.0
    process-1.4.2.0
    rts-1.0
    scientific-0.3.4.7
    split-0.2.3.1
    syb-0.6
    tagged-0.8.5
    template-haskell-2.11.0.0
    text-1.2.2.1
    time-1.6.0.1
    transformers-0.5.2.0
    transformers-compat-0.5.1.4
    unix-2.7.2.0
    unordered-containers-0.2.7.0
    vector-0.11.0.0
@hamishmack
Copy link
Member

I think this has been fixed (probably by ghcjs/shims#41). I get:

$node test.jsexe/all.js
Creating object
Object -> JSVal
Going to Aeson
Evaluated x
$ ghcjs-pkg list
/Users/hamish/.ghcjs/x86_64-darwin-0.2.1-8.0.2/ghcjs/package.conf.d
    Cabal-1.24.0.0
    aeson-0.11.2.0
    array-0.5.1.1
    async-2.1.0
    attoparsec-0.13.0.2
    base-4.9.0.0
    binary-0.8.3.0
    bytestring-0.10.8.1
    case-insensitive-1.2.0.6
    containers-0.5.7.1
    deepseq-1.4.2.0
    directory-1.2.6.2
    dlist-0.7.1.2
    extensible-exceptions-0.1.1.4
    fail-4.9.0.0
    filepath-1.4.1.0
    ghc-8.0.1
    ghc-boot-8.0.1
    ghc-boot-th-8.0.1
    ghc-prim-0.5.0.0
    ghci-8.0.1
    ghcjs-base-0.2.0.0
    ghcjs-prim-0.1.0.0
    ghcjs-th-0.1.0.0
    hashable-1.2.4.0
    integer-gmp-1.0.0.1
    mtl-2.2.2
    parallel-3.2.1.0
    pretty-1.1.3.3
    primitive-0.6.1.0
    process-1.4.2.0
    rts-1.0
    scientific-0.3.4.7
    stm-2.4.4.1
    syb-0.6
    tagged-0.8.4
    template-haskell-2.11.0.0
    text-1.2.2.1
    time-1.6.0.1
    transformers-0.5.2.0
    unix-2.7.2.0
    unordered-containers-0.2.7.0
    vector-0.11.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants