1 // META: title=Encoding API: End-of-file
5 {encoding: 'utf-8', sequence: [0xC0]},
6 {encoding: 'utf-16le', sequence: [0x00]},
7 {encoding: 'utf-16be', sequence: [0x00]}
8 ].forEach(function(testCase) {
10 assert_throws_js(TypeError, function() {
11 var decoder = new TextDecoder(testCase.encoding, {fatal: true});
12 decoder.decode(new Uint8Array(testCase.sequence));
13 }, 'Unterminated ' + testCase.encoding + ' sequence should throw if fatal flag is set');
16 new TextDecoder(testCase.encoding).decode(new Uint8Array([testCase.sequence])),
18 'Unterminated UTF-8 sequence should emit replacement character if fatal flag is unset');
20 }, 'Fatal flag, non-streaming cases');
24 var decoder = new TextDecoder('utf-16le', {fatal: true});
25 var odd = new Uint8Array([0x00]);
26 var even = new Uint8Array([0x00, 0x00]);
28 assert_equals(decoder.decode(odd, {stream: true}), '');
29 assert_equals(decoder.decode(odd), '\u0000');
31 assert_throws_js(TypeError, function() {
32 decoder.decode(even, {stream: true});
36 assert_throws_js(TypeError, function() {
37 decoder.decode(odd, {stream: true});
41 assert_equals(decoder.decode(even, {stream: true}), '\u0000');
42 assert_equals(decoder.decode(even), '\u0000');
44 }, 'Fatal flag, streaming cases');