Open ryantrinkle opened 8 years ago
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.
The code where I encountered this is here: https://github.com/ryantrinkle/reflex-dom/blob/ghcjs-improved-base-2/src-ghcjs/Reflex/Dom/WebSocket/Foreign.hs#L38
This program:
produces the following error:
But, when the
BS.empty
is replaced with a non-empty ByteString, it outputsas expected.