@@ -412,7 +412,13 @@ function makeTextDecoderICU() {
412412 decode ( input = empty , options = kEmptyObject ) {
413413 validateDecoder ( this ) ;
414414 if ( isAnyArrayBuffer ( input ) ) {
415- input = lazyBuffer ( ) . from ( input ) ;
415+ try {
416+ input = lazyBuffer ( ) . from ( input ) ;
417+ } catch {
418+ // If the buffer is detached,
419+ // use an empty Uint8Array to avoid TypeError
420+ input = empty ;
421+ }
416422 } else if ( ! isArrayBufferView ( input ) ) {
417423 throw new ERR_INVALID_ARG_TYPE ( 'input' ,
418424 [ 'ArrayBuffer' , 'ArrayBufferView' ] ,
@@ -485,10 +491,18 @@ function makeTextDecoderJS() {
485491 decode ( input = empty , options = kEmptyObject ) {
486492 validateDecoder ( this ) ;
487493 if ( isAnyArrayBuffer ( input ) ) {
488- input = lazyBuffer ( ) . from ( input ) ;
494+ try {
495+ input = lazyBuffer ( ) . from ( input ) ;
496+ } catch {
497+ input = empty ;
498+ }
489499 } else if ( isArrayBufferView ( input ) ) {
490- input = lazyBuffer ( ) . from ( input . buffer , input . byteOffset ,
491- input . byteLength ) ;
500+ try {
501+ input = lazyBuffer ( ) . from ( input . buffer , input . byteOffset ,
502+ input . byteLength ) ;
503+ } catch {
504+ input = empty ;
505+ }
492506 } else {
493507 throw new ERR_INVALID_ARG_TYPE ( 'input' ,
494508 [ 'ArrayBuffer' , 'ArrayBufferView' ] ,
0 commit comments