2 <title>Encoding API: End-of-file</title>
3 <script src="../../../resources/testharness.js"></script>
4 <script src="../../../resources/testharnessreport.js"></script>
9 {encoding: 'utf-8', sequence: [0xC0]},
10 {encoding: 'utf-16le', sequence: [0x00]},
11 {encoding: 'utf-16be', sequence: [0x00]}
12 ].forEach(function(testCase) {
14 assert_throws({name: 'EncodingError'}, function() {
15 var decoder = new TextDecoder(testCase.encoding, {fatal: true});
16 decoder.decode(new Uint8Array(testCase.sequence));
17 }, 'Unterminated ' + testCase.encoding + ' sequence should throw if fatal flag is set');
20 new TextDecoder(testCase.encoding).decode(new Uint8Array([testCase.sequence])),
22 'Unterminated UTF-8 sequence should emit replacement character if fatal flag is unset');
24 }, 'Fatal flag, non-streaming cases');
28 var decoder = new TextDecoder('utf-16le', {fatal: true});
29 var odd = new Uint8Array([0x00]);
30 var even = new Uint8Array([0x00, 0x00]);
32 assert_equals(decoder.decode(odd, {stream: true}), '');
33 assert_equals(decoder.decode(odd), '\u0000');
35 assert_throws({name: 'EncodingError'}, function() {
36 decoder.decode(even, {stream: true});
40 assert_throws({name: 'EncodingError'}, function() {
41 decoder.decode(odd, {stream: true});
45 assert_equals(decoder.decode(even, {stream: true}), '\u0000');
46 assert_equals(decoder.decode(even), '\u0000');
48 }, 'Fatal flag, streaming cases');