11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// From: https://github.com/w3c/web-platform-tests/blob/39a67e2fff/encoding/textdecoder-utf16-surrogates.html 41cb0ef41Sopenharmony_ci// With the twist that we specifically test for Node.js error codes 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst common = require('../common'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciif (!common.hasIntl) 91cb0ef41Sopenharmony_ci common.skip('missing Intl'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst assert = require('assert'); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst bad = [ 141cb0ef41Sopenharmony_ci { 151cb0ef41Sopenharmony_ci encoding: 'utf-16le', 161cb0ef41Sopenharmony_ci input: [0x00, 0xd8], 171cb0ef41Sopenharmony_ci expected: '\uFFFD', 181cb0ef41Sopenharmony_ci name: 'lone surrogate lead' 191cb0ef41Sopenharmony_ci }, 201cb0ef41Sopenharmony_ci { 211cb0ef41Sopenharmony_ci encoding: 'utf-16le', 221cb0ef41Sopenharmony_ci input: [0x00, 0xdc], 231cb0ef41Sopenharmony_ci expected: '\uFFFD', 241cb0ef41Sopenharmony_ci name: 'lone surrogate trail' 251cb0ef41Sopenharmony_ci }, 261cb0ef41Sopenharmony_ci { 271cb0ef41Sopenharmony_ci encoding: 'utf-16le', 281cb0ef41Sopenharmony_ci input: [0x00, 0xd8, 0x00, 0x00], 291cb0ef41Sopenharmony_ci expected: '\uFFFD\u0000', 301cb0ef41Sopenharmony_ci name: 'unmatched surrogate lead' 311cb0ef41Sopenharmony_ci }, 321cb0ef41Sopenharmony_ci { 331cb0ef41Sopenharmony_ci encoding: 'utf-16le', 341cb0ef41Sopenharmony_ci input: [0x00, 0xdc, 0x00, 0x00], 351cb0ef41Sopenharmony_ci expected: '\uFFFD\u0000', 361cb0ef41Sopenharmony_ci name: 'unmatched surrogate trail' 371cb0ef41Sopenharmony_ci }, 381cb0ef41Sopenharmony_ci { 391cb0ef41Sopenharmony_ci encoding: 'utf-16le', 401cb0ef41Sopenharmony_ci input: [0x00, 0xdc, 0x00, 0xd8], 411cb0ef41Sopenharmony_ci expected: '\uFFFD\uFFFD', 421cb0ef41Sopenharmony_ci name: 'swapped surrogate pair' 431cb0ef41Sopenharmony_ci }, 441cb0ef41Sopenharmony_ci]; 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_cibad.forEach((t) => { 471cb0ef41Sopenharmony_ci assert.throws( 481cb0ef41Sopenharmony_ci () => { 491cb0ef41Sopenharmony_ci new TextDecoder(t.encoding, { fatal: true }) 501cb0ef41Sopenharmony_ci .decode(new Uint8Array(t.input)); 511cb0ef41Sopenharmony_ci }, { 521cb0ef41Sopenharmony_ci code: 'ERR_ENCODING_INVALID_ENCODED_DATA', 531cb0ef41Sopenharmony_ci name: 'TypeError' 541cb0ef41Sopenharmony_ci } 551cb0ef41Sopenharmony_ci ); 561cb0ef41Sopenharmony_ci}); 57