1// META: title=Encoding API: USVString surrogate handling when encoding 2 3var bad = [ 4 { 5 input: '\uD800', 6 expected: '\uFFFD', 7 name: 'lone surrogate lead' 8 }, 9 { 10 input: '\uDC00', 11 expected: '\uFFFD', 12 name: 'lone surrogate trail' 13 }, 14 { 15 input: '\uD800\u0000', 16 expected: '\uFFFD\u0000', 17 name: 'unmatched surrogate lead' 18 }, 19 { 20 input: '\uDC00\u0000', 21 expected: '\uFFFD\u0000', 22 name: 'unmatched surrogate trail' 23 }, 24 { 25 input: '\uDC00\uD800', 26 expected: '\uFFFD\uFFFD', 27 name: 'swapped surrogate pair' 28 }, 29 { 30 input: '\uD834\uDD1E', 31 expected: '\uD834\uDD1E', 32 name: 'properly encoded MUSICAL SYMBOL G CLEF (U+1D11E)' 33 } 34]; 35 36bad.forEach(function(t) { 37 test(function() { 38 var encoded = new TextEncoder().encode(t.input); 39 var decoded = new TextDecoder().decode(encoded); 40 assert_equals(decoded, t.expected); 41 }, 'USVString handling: ' + t.name); 42}); 43 44test(function() { 45 assert_equals(new TextEncoder().encode().length, 0, 'Should default to empty string'); 46}, 'USVString default'); 47