Skip to main content

text_decode

Function text_decode 

Source
pub(crate) fn text_decode(
    _it: &mut Interp,
    this: Value,
    a: &[Value],
) -> Result<Value, Value>
Expand description

TextDecoder.prototype.decode()。以前はコンストラクタに渡した encoding ラベル(new TextDecoder('utf-16le') 等)を完全に無視し、常に UTF-8 として デコードしていたバグだった(utf-16 系データを渡しても静かに文字化けする)。 重要: decode(chunk, {stream: true})(ストリーミングデコード。丸ごと 未対応だった。チャンク境界でマルチバイト文字が分断された場合に文字化け させず次回呼び出しへ持ち越す定番パターン)にも対応。this._pending (隠しプロパティ)に前回分の未完了バイトを保持する。UTF-16 系は2バイト 単位のため奇数バイト余りを同様に持ち越す。