@@ -75,6 +75,7 @@ const {
7575const {
7676 customInspectSymbol,
7777 isInsideNodeModules,
78+ lazyDOMException,
7879 normalizeEncoding,
7980 kIsEncodingSymbol
8081} = require ( 'internal/util' ) ;
@@ -1208,22 +1209,14 @@ if (internalBinding('config').hasIntl) {
12081209 } ;
12091210}
12101211
1211- let DOMException ;
1212-
1213- const lazyInvalidCharError = hideStackFrames ( ( message , name ) => {
1214- if ( DOMException === undefined )
1215- DOMException = internalBinding ( 'messaging' ) . DOMException ;
1216- throw new DOMException ( 'Invalid character' , 'InvalidCharacterError' ) ;
1217- } ) ;
1218-
12191212function btoa (
8000
input ) {
12201213 // The implementation here has not been performance optimized in any way and
12211214 // should not be.
12221215 // Refs: https://github.com/nodejs/node/pull/38433#issuecomment-828426932
12231216 input = `${ input } ` ;
12241217 for ( let n = 0 ; n < input . length ; n ++ ) {
12251218 if ( input [ n ] . charCodeAt ( 0 ) > 0xff )
1226- lazyInvalidCharError ( ) ;
1219+ throw lazyDOMException ( 'Invalid character' , 'InvalidCharacterError' ) ;
12271220 }
12281221 const buf = Buffer . from ( input , 'latin1' ) ;
12291222 return buf . toString ( 'base64' ) ;
@@ -1239,7 +1232,7 @@ function atob(input) {
12391232 input = `${ input } ` ;
12401233 for ( let n = 0 ; n < input . length ; n ++ ) {
12411234 if ( ! kBase64Digits . includes ( input [ n ] ) )
1242- lazyInvalidCharError ( ) ;
1235+ throw lazyDOMException ( 'Invalid character' , 'InvalidCharacterError' ) ;
12431236 }
12441237 return Buffer . from ( input , 'base64' ) . toString ( 'latin1' ) ;
12451238}
0 commit comments