{"action":"created","issue":{"url":"https://api.github.com/repos/ghcjs/ghcjs-base/issues/8","labels_url":"https://api.github.com/repos/ghcjs/ghcjs-base/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/ghcjs/ghcjs-base/issues/8/comments","events_url":"https://api.github.com/repos/ghcjs/ghcjs-base/issues/8/events","html_url":"https://github.com/ghcjs/ghcjs-base/issues/8","id":44101918,"number":8,"title":"Converting `undefined` value to Text","user":{"login":"geraldus","id":744471,"avatar_url":"https://avatars.githubusercontent.com/u/744471?v=3","gravatar_id":"","url":"https://api.github.com/users/geraldus","html_url":"https://github.com/geraldus","followers_url":"https://api.github.com/users/geraldus/followers","following_url":"https://api.github.com/users/geraldus/following{/other_user}","gists_url":"https://api.github.com/users/geraldus/gists{/gist_id}","starred_url":"https://api.github.com/users/geraldus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geraldus/subscriptions","organizations_url":"https://api.github.com/users/geraldus/orgs","repos_url":"https://api.github.com/users/geraldus/repos","events_url":"https://api.github.com/users/geraldus/events{/privacy}","received_events_url":"https://api.github.com/users/geraldus/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2014-09-26T20:16:07Z","updated_at":"2015-01-12T18:32:42Z","closed_at":"2015-01-04T20:33:13Z","body":"I faced some issue when tried to convert an `undefined` javascript value to `Text` with `fromJSRef_fromJSString`.\r\nConsider following code:\r\n``` haskell\r\nforeign import javascript safe\r\n    \"$r = (function(){\\\r\n    \\    if (window.config) { return window.config[$1]; }\\\r\n    \\    else { return undefined; }\\\r\n    \\}())\"\r\n    js_get_config_of :: JSString -> IO (JSRef a)\r\nconfigRefByName :: ToJSString a => a -> IO (JSRef b)\r\nconfigRefByName = js_get_config_of . toJSString\r\n```\r\nThis is quite simple code to read globally stored configuration, if there is no configuration, `undefined` value will be returned.\r\nConverting undefined value to String works, but a bit strange:\r\n``` haskell\r\ndo\r\n    undefRef <- configRefByName \"not defined\"\r\n    str <- fromJSRef_fromJSString undefRef :: IO (Maybe String)\r\n    print str\r\n```\r\nThis prints `Just \"\"`, though I supposed to see `Nothing` in this case. At least it works.\r\nIf I change result type to `IO (Maybe Text)` I'm facing runtime exception:\r\n> uncaught exception in Haskell main thread: TypeError: Cannot read property 'length' of undefined\r\n\r\nObviously, marshall code does not check if value actually valid and just treats it like array of chars (or something), and tries to read length of it."},"comment":{"url":"https://api.github.com/repos/ghcjs/ghcjs-base/issues/comments/69619704","html_url":"https://github.com/ghcjs/ghcjs-base/issues/8#issuecomment-69619704","issue_url":"https://api.github.com/repos/ghcjs/ghcjs-base/issues/8","id":69619704,"user":{"login":"geraldus","id":744471,"avatar_url":"https://avatars.githubusercontent.com/u/744471?v=3","gravatar_id":"","url":"https://api.github.com/users/geraldus","html_url":"https://github.com/geraldus","followers_url":"https://api.github.com/users/geraldus/followers","following_url":"https://api.github.com/users/geraldus/following{/other_user}","gists_url":"https://api.github.com/users/geraldus/gists{/gist_id}","starred_url":"https://api.github.com/users/geraldus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geraldus/subscriptions","organizations_url":"https://api.github.com/users/geraldus/orgs","repos_url":"https://api.github.com/users/geraldus/repos","events_url":"https://api.github.com/users/geraldus/events{/privacy}","received_events_url":"https://api.github.com/users/geraldus/received_events","type":"User","site_admin":false},"created_at":"2015-01-12T18:32:42Z","updated_at":"2015-01-12T18:32:42Z","body":"Amazing, very appreciate!"}}