File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,12 +62,13 @@ export class TextDecoder {
6262 if ( typeof options !== 'object' ) throw new TypeError ( E_OPTIONS )
6363 const stream = Boolean ( options . stream )
6464 let u = input === undefined ? new Uint8Array ( ) : fromSource ( input )
65+ const empty = u . length === 0 // also can't be streaming after next line
66+ if ( empty && stream ) return '' // no state change
6567
6668 if ( this . #unicode) {
6769 let prefix
6870 if ( this . #chunk) {
69- if ( u . length === 0 ) {
70- if ( stream ) return '' // no change
71+ if ( empty ) {
7172 u = this . #chunk // process as final chunk to handle errors and state changes
7273 } else if ( u . length < 3 ) {
7374 // No reason to bruteforce offsets, also it's possible this doesn't yet end the sequence
@@ -96,8 +97,8 @@ export class TextDecoder {
9697 }
9798
9899 this . #chunk = null
99- } else if ( u . byteLength === 0 ) {
100- if ( ! stream ) this . #canBOM = ! this . ignoreBOM
100+ } else if ( empty ) {
101+ this . #canBOM = ! this . ignoreBOM // not streaming
101102 return ''
102103 }
103104
You can’t perform that action at this time.
0 commit comments