Commit Graph
2 Commits
Author SHA1 Message Date
Chris Tate 5f602ff3b8 Decode asserted optional typed arrays other than Uint8Array
`decoder.decode(view!)` on a `Uint16Array | undefined` (or another typed
array that may be undefined) was refused with SC2020: the assertion keeps
the undefined arm for decode, and the decode input only read the
undefined arm of `Uint8Array | undefined`. The undefined arm of any typed
array that may be undefined now reads as an empty array of the same type,
so a defined input decodes its bytes and an undefined one decodes no
bytes, as in Node.
2026-10-24 21:16:59 -05:00
Chris Tate 4c0572c49e Decode an undefined TextDecoder input as no bytes
In Node, `decoder.decode(undefined)` returns "" like `decode()`, and
flushes bytes pending from streamed input. scriptc refused a statically
undefined argument and an argument typed `Uint8Array | undefined` with
SC2020, and `decode(x!)` on an undefined value threw a TypeError.

The decode input lowering now evaluates a statically undefined argument
for its effects and decodes an empty Uint8Array, and reads the undefined
arm of `Uint8Array | undefined` as an empty Uint8Array, in both the
decoder-value and the `new TextDecoder(label).decode(...)` paths. A
non-null assertion passed to decode keeps the undefined it removes,
instead of the checked narrowing other optional standard library
parameters keep. Inputs that may be null are refused as before (`decode(null)`
throws a TypeError in Node).
2026-10-24 06:25:57 -05:00