OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <title>Encoding API: UTF-16 surrogate handling</title> | |
3 <script src="../../../resources/testharness.js"></script> | |
4 <script src="../../../resources/testharnessreport.js"></script> | |
5 <script> | |
6 | |
7 var bad = [ | |
8 { | |
9 encoding: 'utf-16le', | |
10 input: [0x00, 0xd8], | |
11 expected: '\uFFFD', | |
12 name: 'lone surrogate lead' | |
13 }, | |
14 { | |
15 encoding: 'utf-16le', | |
16 input: [0x00, 0xdc], | |
17 expected: '\uFFFD', | |
18 name: 'lone surrogate trail' | |
19 }, | |
20 { | |
21 encoding: 'utf-16le', | |
22 input: [0x00, 0xd8, 0x00, 0x00], | |
23 expected: '\uFFFD\u0000', | |
24 name: 'unmatched surrogate lead' | |
25 }, | |
26 { | |
27 encoding: 'utf-16le', | |
28 input: [0x00, 0xdc, 0x00, 0x00], | |
29 expected: '\uFFFD\u0000', | |
30 name: 'unmatched surrogate trail' | |
31 }, | |
32 { | |
33 encoding: 'utf-16le', | |
34 input: [0x00, 0xdc, 0x00, 0xd8], | |
35 expected: '\uFFFD\uFFFD', | |
36 name: 'swapped surrogate pair' | |
37 } | |
38 ]; | |
39 | |
40 bad.forEach(function(t) { | |
41 test(function() { | |
42 assert_equals(new TextDecoder(t.encoding).decode(new Uint8Array(t.input)
), t.expected); | |
43 }, t.encoding + ' - ' + t.name); | |
44 test(function() { | |
45 assert_throws(new TypeError(), function() { | |
46 new TextDecoder(t.encoding, {fatal: true}).decode(new Uint8Array(t.i
nput)) | |
47 }); | |
48 }, t.encoding + ' - ' + t.name + ' (fatal flag set)'); | |
49 }); | |
50 | |
51 </script> | |
OLD | NEW |