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 src="resources/shared.js"></script>
13 name: 'lone surrogate lead'
19 name: 'lone surrogate trail'
23 input: [0x00, 0xd8, 0x00, 0x00],
24 expected: '\uFFFD\u0000',
25 name: 'unmatched surrogate lead'
29 input: [0x00, 0xdc, 0x00, 0x00],
30 expected: '\uFFFD\u0000',
31 name: 'unmatched surrogate trail'
35 input: [0x00, 0xdc, 0x00, 0xd8],
36 expected: '\uFFFD\uFFFD',
37 name: 'swapped surrogate pair'
41 bad.forEach(function(t) {
43 assert_equals(new TextDecoder(t.encoding).decode(new Uint8Array(t.input)), t.expected);
44 }, t.encoding + ' - ' + t.name);
46 assert_throws({name: 'EncodingError'}, function() {
47 new TextDecoder(t.encoding, {fatal: true}).decode(new Uint8Array(t.input))
49 }, t.encoding + ' - ' + t.name + ' (fatal flag set)');