You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{-# LANGUAGE ForeignFunctionInterface, JavaScriptFFI #-}
importqualifiedData.ByteStringasBSimportGHCJS.TypesimportGHCJS.Buffermain::IO()
main =dolet (b, _, _) = fromByteString BS.empty
consoleLog $ jsval $ getArrayBuffer b
foreignimport javascript safe"console.log($1)" consoleLog ::JSVal->IO()
produces the following error:
uncaught exception in Haskell main thread: TypeError: Cannot read property 'buf' of null
TypeError: Cannot read property 'buf' of null
at h$$k4 (/home/ryan/try-reflex22/fromByteStringIssue.jsexe/all.js:37401:57)
at h$runThreadSlice (/home/ryan/try-reflex22/fromByteStringIssue.jsexe/all.js:9790:11)
at h$runThreadSliceCatch (/home/ryan/try-reflex22/fromByteStringIssue.jsexe/all.js:9741:12)
at Immediate.h$mainLoop (/home/ryan/try-reflex22/fromByteStringIssue.jsexe/all.js:9736:9)
at processImmediate [as _immediateCallback] (timers.js:374:17)
But, when the BS.empty is replaced with a non-empty ByteString, it outputs
ArrayBuffer {}
as expected.
The text was updated successfully, but these errors were encountered:
Hmm, good catch. GHCJS does not allocate a buffer of size 0 for empty buffers.
GHC HEAD also adds some resizable ByteArray# operations, which may make it necessary to move getArrayBuffer into IO. Should it throw an exception when there's no buffer? should it return a Maybe or Nullable type instead? or perhaps return a dummy buffer?
in my use case, I need to send the buffer along to WebSocket's send method, so I need a dummy, ultimately. However, I don't mind converting from Maybe/Nullable as necessary - whatever makes the most sense to you (or has the best performance) is fine with me.
This program:
produces the following error:
But, when the
BS.empty
is replaced with a non-empty ByteString, it outputsas expected.
The text was updated successfully, but these errors were encountered: