• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// META: timeout=long
2// META: title=Encoding API: Fatal flag for single byte encodings
3// META: timeout=long
4// META: variant=?1-1000
5// META: variant=?1001-2000
6// META: variant=?2001-3000
7// META: variant=?3001-4000
8// META: variant=?4001-5000
9// META: variant=?5001-6000
10// META: variant=?6001-7000
11// META: variant=?7001-last
12// META: script=/common/subset-tests.js
13
14var singleByteEncodings = [
15     {encoding: 'IBM866', bad: []},
16     {encoding: 'ISO-8859-2', bad: []},
17     {encoding: 'ISO-8859-3', bad: [0xA5, 0xAE, 0xBE, 0xC3, 0xD0, 0xE3, 0xF0]},
18     {encoding: 'ISO-8859-4', bad: []},
19     {encoding: 'ISO-8859-5', bad: []},
20     {encoding: 'ISO-8859-6', bad: [0xA1, 0xA2, 0xA3, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBC, 0xBD, 0xBE, 0xC0, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF]},
21     {encoding: 'ISO-8859-7', bad: [0xAE, 0xD2, 0xFF]},
22     {encoding: 'ISO-8859-8', bad: [0xA1, 0xBF, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xFB, 0xFC, 0xFF]},
23     {encoding: 'ISO-8859-8-I', bad: [0xA1, 0xBF, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xFB, 0xFC, 0xFF]},
24     {encoding: 'ISO-8859-10', bad: []},
25     {encoding: 'ISO-8859-13', bad: []},
26     {encoding: 'ISO-8859-14', bad: []},
27     {encoding: 'ISO-8859-15', bad: []},
28     {encoding: 'ISO-8859-16', bad: []},
29     {encoding: 'KOI8-R', bad: []},
30     {encoding: 'KOI8-U', bad: []},
31     {encoding: 'macintosh', bad: []},
32     {encoding: 'windows-874', bad: [0xDB, 0xDC, 0xDD, 0xDE, 0xFC, 0xFD, 0xFE, 0xFF]},
33     {encoding: 'windows-1250', bad: []},
34     {encoding: 'windows-1251', bad: []},
35     {encoding: 'windows-1252', bad: []},
36     {encoding: 'windows-1253', bad: [0xAA, 0xD2, 0xFF]},
37     {encoding: 'windows-1254', bad: []},
38     {encoding: 'windows-1255', bad: [0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xFB, 0xFC, 0xFF]},
39     {encoding: 'windows-1256', bad: []},
40     {encoding: 'windows-1257', bad: [0xA1, 0xA5]},
41     {encoding: 'windows-1258', bad: []},
42     {encoding: 'x-mac-cyrillic', bad: []},
43];
44
45singleByteEncodings.forEach(function(t) {
46    for (var i = 0; i < 256; ++i) {
47        if (t.bad.indexOf(i) != -1) {
48            subsetTest(test, function() {
49                assert_throws_js(TypeError, function() {
50                    new TextDecoder(t.encoding, {fatal: true}).decode(new Uint8Array([i]));
51                });
52            }, 'Throw due to fatal flag: ' + t.encoding + ' doesn\'t have a pointer ' + i);
53        }
54        else {
55            subsetTest(test, function() {
56                assert_equals(typeof new TextDecoder(t.encoding, {fatal: true}).decode(new Uint8Array([i])), "string");
57            }, 'Not throw: ' + t.encoding + ' has a pointer ' + i);
58        }
59    }
60});
61