@@ -406,7 +406,8 @@ encodeUtf8 (Text arr off len)
406406 memcpy ptr' ptr (fromIntegral utf8len)
407407 return (PS fp' 0 utf8len)
408408#else
409−encodeUtf8 (Text txt) = toByteString 0 (Just (js_length txt)) $ js_encodeUtf8 txt
409+encodeUtf8 (Text txt) = toByteString 0 (Just (byteLength buf - 1)) buf
410+ where buf = js_encodeUtf8 txt
410411#endif
411412
412413-- | Decode text from little endian UTF-16 encoding.
@@ -503,5 +504,4 @@ foreign import ccall unsafe "_hs_text_encode_utf8" c_encode_utf8
503504#else
504505foreign import javascript unsafe "h$textFromString" js_fromString :: JSString -> (# ByteArray#, Int# #)
505506foreign import javascript unsafe "h$encodeUtf8($1)" js_encodeUtf8 :: JSString -> Buffer
506−foreign import javascript unsafe "$1['length']" js_length :: JSString -> Int
507507#endif