| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <title>Encoding API: Fatal flag</title> | |
| 3 <script src="../../../resources/testharness.js"></script> | |
| 4 <script src="../../../resources/testharnessreport.js"></script> | |
| 5 <script> | |
| 6 | |
| 7 var bad = [ | |
| 8 { encoding: 'utf-8', input: [0xFF], name: 'invalid code' }, | |
| 9 { encoding: 'utf-8', input: [0xC0], name: 'ends early' }, | |
| 10 { encoding: 'utf-8', input: [0xE0], name: 'ends early 2' }, | |
| 11 { encoding: 'utf-8', input: [0xC0, 0x00], name: 'invalid trail' }, | |
| 12 { encoding: 'utf-8', input: [0xC0, 0xC0], name: 'invalid trail 2' }, | |
| 13 { encoding: 'utf-8', input: [0xE0, 0x00], name: 'invalid trail 3' }, | |
| 14 { encoding: 'utf-8', input: [0xE0, 0xC0], name: 'invalid trail 4' }, | |
| 15 { encoding: 'utf-8', input: [0xE0, 0x80, 0x00], name: 'invalid trail 5' }, | |
| 16 { encoding: 'utf-8', input: [0xE0, 0x80, 0xC0], name: 'invalid trail 6' }, | |
| 17 { encoding: 'utf-8', input: [0xFC, 0x80, 0x80, 0x80, 0x80, 0x80], name: '> 0
x10FFFF' }, | |
| 18 { encoding: 'utf-8', input: [0xFE, 0x80, 0x80, 0x80, 0x80, 0x80], name: 'obs
olete lead byte' }, | |
| 19 | |
| 20 // Overlong encodings | |
| 21 { encoding: 'utf-8', input: [0xC0, 0x80], name: 'overlong U+0000 - 2 bytes'
}, | |
| 22 { encoding: 'utf-8', input: [0xE0, 0x80, 0x80], name: 'overlong U+0000 - 3 b
ytes' }, | |
| 23 { encoding: 'utf-8', input: [0xF0, 0x80, 0x80, 0x80], name: 'overlong U+0000
- 4 bytes' }, | |
| 24 { encoding: 'utf-8', input: [0xF8, 0x80, 0x80, 0x80, 0x80], name: 'overlong
U+0000 - 5 bytes' }, | |
| 25 { encoding: 'utf-8', input: [0xFC, 0x80, 0x80, 0x80, 0x80, 0x80], name: 'ove
rlong U+0000 - 6 bytes' }, | |
| 26 | |
| 27 { encoding: 'utf-8', input: [0xC1, 0xBF], name: 'overlong U+007F - 2 bytes'
}, | |
| 28 { encoding: 'utf-8', input: [0xE0, 0x81, 0xBF], name: 'overlong U+007F - 3 b
ytes' }, | |
| 29 { encoding: 'utf-8', input: [0xF0, 0x80, 0x81, 0xBF], name: 'overlong U+007F
- 4 bytes' }, | |
| 30 { encoding: 'utf-8', input: [0xF8, 0x80, 0x80, 0x81, 0xBF], name: 'overlong
U+007F - 5 bytes' }, | |
| 31 { encoding: 'utf-8', input: [0xFC, 0x80, 0x80, 0x80, 0x81, 0xBF], name: 'ove
rlong U+007F - 6 bytes' }, | |
| 32 | |
| 33 { encoding: 'utf-8', input: [0xE0, 0x9F, 0xBF], name: 'overlong U+07FF - 3 b
ytes' }, | |
| 34 { encoding: 'utf-8', input: [0xF0, 0x80, 0x9F, 0xBF], name: 'overlong U+07FF
- 4 bytes' }, | |
| 35 { encoding: 'utf-8', input: [0xF8, 0x80, 0x80, 0x9F, 0xBF], name: 'overlong
U+07FF - 5 bytes' }, | |
| 36 { encoding: 'utf-8', input: [0xFC, 0x80, 0x80, 0x80, 0x9F, 0xBF], name: 'ove
rlong U+07FF - 6 bytes' }, | |
| 37 | |
| 38 { encoding: 'utf-8', input: [0xF0, 0x8F, 0xBF, 0xBF], name: 'overlong U+FFFF
- 4 bytes' }, | |
| 39 { encoding: 'utf-8', input: [0xF8, 0x80, 0x8F, 0xBF, 0xBF], name: 'overlong
U+FFFF - 5 bytes' }, | |
| 40 { encoding: 'utf-8', input: [0xFC, 0x80, 0x80, 0x8F, 0xBF, 0xBF], name: 'ove
rlong U+FFFF - 6 bytes' }, | |
| 41 | |
| 42 { encoding: 'utf-8', input: [0xF8, 0x84, 0x8F, 0xBF, 0xBF], name: 'overlong
U+10FFFF - 5 bytes' }, | |
| 43 { encoding: 'utf-8', input: [0xFC, 0x80, 0x84, 0x8F, 0xBF, 0xBF], name: 'ove
rlong U+10FFFF - 6 bytes' }, | |
| 44 | |
| 45 // UTF-16 surrogates encoded as code points in UTF-8 | |
| 46 { encoding: 'utf-8', input: [0xED, 0xA0, 0x80], name: 'lead surrogate' }, | |
| 47 { encoding: 'utf-8', input: [0xED, 0xB0, 0x80], name: 'trail surrogate' }, | |
| 48 { encoding: 'utf-8', input: [0xED, 0xA0, 0x80, 0xED, 0xB0, 0x80], name: 'sur
rogate pair' }, | |
| 49 | |
| 50 { encoding: 'utf-16le', input: [0x00], name: 'truncated code unit' }, | |
| 51 // Mismatched UTF-16 surrogates are exercised in utf16-surrogates.html | |
| 52 | |
| 53 // FIXME: Add legacy encoding cases | |
| 54 ]; | |
| 55 | |
| 56 bad.forEach(function(t) { | |
| 57 test(function() { | |
| 58 assert_throws(new TypeError(), function() { | |
| 59 new TextDecoder(t.encoding, {fatal: true}).decode(new Uint8Array(t.i
nput)) | |
| 60 }); | |
| 61 }, 'Fatal flag: ' + t.encoding + ' - ' + t.name); | |
| 62 }); | |
| 63 | |
| 64 test(function() { | |
| 65 assert_true('fatal' in new TextDecoder(), 'The fatal attribute should exist
on TextDecoder.'); | |
| 66 assert_equals(typeof new TextDecoder().fatal, 'boolean', 'The type of the f
atal attribute should be boolean.'); | |
| 67 assert_false(new TextDecoder().fatal, 'The fatal attribute should default to
false.'); | |
| 68 assert_true(new TextDecoder('utf-8', {fatal: true}).fatal, 'The fatal attrib
ute can be set using an option.'); | |
| 69 | |
| 70 }, 'The fatal attribute of TextDecoder'); | |
| 71 | |
| 72 </script> | |
| OLD | NEW |