1// META: title=Encoding API: TextDecoder decode() optional arguments 2 3test(t => { 4 const decoder = new TextDecoder(); 5 6 // Just passing nothing. 7 assert_equals( 8 decoder.decode(undefined), '', 9 'Undefined as first arg should decode to empty string'); 10 11 // Flushing an incomplete sequence. 12 decoder.decode(new Uint8Array([0xc9]), {stream: true}); 13 assert_equals( 14 decoder.decode(undefined), '\uFFFD', 15 'Undefined as first arg should flush the stream'); 16 17}, 'TextDecoder decode() with explicit undefined'); 18 19test(t => { 20 const decoder = new TextDecoder(); 21 22 // Just passing nothing. 23 assert_equals( 24 decoder.decode(undefined, undefined), '', 25 'Undefined as first arg should decode to empty string'); 26 27 // Flushing an incomplete sequence. 28 decoder.decode(new Uint8Array([0xc9]), {stream: true}); 29 assert_equals( 30 decoder.decode(undefined, undefined), '\uFFFD', 31 'Undefined as first arg should flush the stream'); 32 33}, 'TextDecoder decode() with undefined and undefined'); 34 35test(t => { 36 const decoder = new TextDecoder(); 37 38 // Just passing nothing. 39 assert_equals( 40 decoder.decode(undefined, {}), '', 41 'Undefined as first arg should decode to empty string'); 42 43 // Flushing an incomplete sequence. 44 decoder.decode(new Uint8Array([0xc9]), {stream: true}); 45 assert_equals( 46 decoder.decode(undefined, {}), '\uFFFD', 47 'Undefined as first arg should flush the stream'); 48 49}, 'TextDecoder decode() with undefined and options'); 50