Skip to content

Polyfill produces invalid results #34

@ChALkeR

Description

@ChALkeR

On non-Node.js without XHR+Blob, this uses Buffer polyfill when available. And Buffer polyfill is slow and buggy.

Specific issue:

delete globalThis.TextDecoder
delete globalThis.TextEncoder
require('fast-text-encoding')
console.log(new TextDecoder().decode(Uint8Array.of(0xf0, 0x90, 0x80)).length)
console.log(new TextEncoder().encode('\ud800\ud800'))

Node.js:

1
<Buffer ef bf bd ef bf bd>

Hermes:

3
<Buffer ef bf bd>

Also, why does it return Buffer instances?


And without Buffer global this is even worse:

delete globalThis.TextDecoder
delete globalThis.TextEncoder
delete globalThis.Buffer
require('fast-text-encoding')
console.log(new TextDecoder().decode(Uint8Array.of(0xf0, 0x90, 0x80)).length)
console.log(new TextEncoder().encode('\ud800\ud800'))
2
Uint8Array(0) []

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions