@@ -145,6 +145,16 @@ describe('random data', () => {
145145 const restored = [ ]
146146 const ignoreBOM = true
147147
148+ let nativeFatal = nativeDecoder
149+ if ( nativeFatal ) {
150+ try {
151+ // Non-fixed Node.js without ICU doesn't have 'fatal' option support
152+ new TextDecoder ( 'utf8' , { fatal : true } ) // eslint-disable-line no-new
153+ } catch {
154+ nativeFatal = false
155+ }
156+ }
157+
148158 test ( 'utf8toStringLoose' , ( t ) => {
149159 const textDecoder = nativeDecoder ? new TextDecoder ( 'utf8' , { ignoreBOM } ) : null // polyfilled might be wrong
150160 const NativeBuffer = globalThis . Buffer && ! globalThis . Buffer . TYPED_ARRAY_SUPPORT ? Buffer : null
@@ -158,7 +168,7 @@ describe('random data', () => {
158168 } )
159169
160170 test ( 'utf8toString (ascii)' , ( t ) => {
161- const textDecoder = nativeDecoder ? new TextDecoder ( 'utf8' , { fatal : true , ignoreBOM } ) : null
171+ const textDecoder = nativeFatal ? new TextDecoder ( 'utf8' , { fatal : true , ignoreBOM } ) : null
162172 for ( const u8 of poolAscii ) {
163173 const str = utf8toString ( u8 )
164174 t . assert . strictEqual ( str , utf8toStringLoose ( u8 ) )
@@ -171,7 +181,7 @@ describe('random data', () => {
171181 } )
172182
173183 test ( 'utf8toString' , ( t ) => {
174- const textDecoder = nativeDecoder ? new TextDecoder ( 'utf8' , { fatal : true , ignoreBOM } ) : null
184+ const textDecoder = nativeFatal ? new TextDecoder ( 'utf8' , { fatal : true , ignoreBOM } ) : null
175185 t . assert . strictEqual ( strings . length , pool . length )
176186 for ( let i = 0 ; i < pool . length ; i ++ ) {
177187 const u8 = pool [ i ]
@@ -227,7 +237,7 @@ describe('random data', () => {
227237 } )
228238
229239 test ( 'utf8toString / utf8toStringLoose' , ( t ) => {
230- const textDecoder = nativeDecoder ? new TextDecoder ( 'utf8' , { fatal : true , ignoreBOM } ) : null
240+ const textDecoder = nativeFatal ? new TextDecoder ( 'utf8' , { fatal : true , ignoreBOM } ) : null
231241 t . assert . strictEqual ( strings . length , pool . length )
232242 for ( let i = 0 ; i < pool . length ; i ++ ) {
233243 const str = strings [ i ]
0 commit comments