11cb0ef41Sopenharmony_ci// META: title=Encoding API: UTF-16 surrogate handling 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_civar bad = [ 41cb0ef41Sopenharmony_ci { 51cb0ef41Sopenharmony_ci encoding: 'utf-16le', 61cb0ef41Sopenharmony_ci input: [0x00, 0xd8], 71cb0ef41Sopenharmony_ci expected: '\uFFFD', 81cb0ef41Sopenharmony_ci name: 'lone surrogate lead' 91cb0ef41Sopenharmony_ci }, 101cb0ef41Sopenharmony_ci { 111cb0ef41Sopenharmony_ci encoding: 'utf-16le', 121cb0ef41Sopenharmony_ci input: [0x00, 0xdc], 131cb0ef41Sopenharmony_ci expected: '\uFFFD', 141cb0ef41Sopenharmony_ci name: 'lone surrogate trail' 151cb0ef41Sopenharmony_ci }, 161cb0ef41Sopenharmony_ci { 171cb0ef41Sopenharmony_ci encoding: 'utf-16le', 181cb0ef41Sopenharmony_ci input: [0x00, 0xd8, 0x00, 0x00], 191cb0ef41Sopenharmony_ci expected: '\uFFFD\u0000', 201cb0ef41Sopenharmony_ci name: 'unmatched surrogate lead' 211cb0ef41Sopenharmony_ci }, 221cb0ef41Sopenharmony_ci { 231cb0ef41Sopenharmony_ci encoding: 'utf-16le', 241cb0ef41Sopenharmony_ci input: [0x00, 0xdc, 0x00, 0x00], 251cb0ef41Sopenharmony_ci expected: '\uFFFD\u0000', 261cb0ef41Sopenharmony_ci name: 'unmatched surrogate trail' 271cb0ef41Sopenharmony_ci }, 281cb0ef41Sopenharmony_ci { 291cb0ef41Sopenharmony_ci encoding: 'utf-16le', 301cb0ef41Sopenharmony_ci input: [0x00, 0xdc, 0x00, 0xd8], 311cb0ef41Sopenharmony_ci expected: '\uFFFD\uFFFD', 321cb0ef41Sopenharmony_ci name: 'swapped surrogate pair' 331cb0ef41Sopenharmony_ci } 341cb0ef41Sopenharmony_ci]; 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_cibad.forEach(function(t) { 371cb0ef41Sopenharmony_ci test(function() { 381cb0ef41Sopenharmony_ci assert_equals(new TextDecoder(t.encoding).decode(new Uint8Array(t.input)), t.expected); 391cb0ef41Sopenharmony_ci }, t.encoding + ' - ' + t.name); 401cb0ef41Sopenharmony_ci test(function() { 411cb0ef41Sopenharmony_ci assert_throws_js(TypeError, function() { 421cb0ef41Sopenharmony_ci new TextDecoder(t.encoding, {fatal: true}).decode(new Uint8Array(t.input)) 431cb0ef41Sopenharmony_ci }); 441cb0ef41Sopenharmony_ci }, t.encoding + ' - ' + t.name + ' (fatal flag set)'); 451cb0ef41Sopenharmony_ci}); 46