1+ // Flags: --expose-internals
12'use strict' ;
23
34require ( '../common' ) ;
45
56const { strictEqual, throws } = require ( 'assert' ) ;
67const buffer = require ( 'buffer' ) ;
78
9+ const { internalBinding } = require ( 'internal/test/binding' ) ;
10+ const { DOMException } = internalBinding ( 'messaging' ) ;
11+
812// Exported on the global object
913strictEqual ( globalThis . atob , buffer . atob ) ;
1014strictEqual ( globalThis . btoa , buffer . btoa ) ;
@@ -14,4 +18,26 @@ throws(() => buffer.atob(), /TypeError/);
1418throws ( ( ) => buffer . btoa ( ) , / T y p e E r r o r / ) ;
1519
1620strictEqual ( atob ( ' ' ) , '' ) ;
17- strictEqual ( atob ( ' YW\tJ\njZA=\r= ' ) , 'abcd' ) ;
21+ strictEqual ( atob ( ' Y\fW\tJ\njZ A=\r= ' ) , 'abcd' ) ;
22+
23+ strictEqual ( atob ( null ) , '\x9Eée' ) ;
24+ strictEqual ( atob ( NaN ) , '5£' ) ;
25+ strictEqual ( atob ( Infinity ) , '"wâ\x9E+r' ) ;
26+ strictEqual ( atob ( true ) , '¶»\x9E' ) ;
27+ strictEqual ( atob ( 1234 ) , '×mø' ) ;
28+ strictEqual ( atob ( [ ] ) , '' ) ;
29+ strictEqual ( atob ( { toString : ( ) => '' } ) , '' ) ;
30+ strictEqual ( atob ( { [ Symbol . toPrimitive ] : ( ) => '' } ) , '' ) ;
31+
32+ throws ( ( ) => atob ( Symbol ( ) ) , / T y p e E r r o r / ) ;
33+ [
34+ undefined , false , ( ) => { } , { } , [ 1 ] ,
35+ 0 , 1 , 0n , 1n , - Infinity ,
36+ 'a' , 'a\n\n\n' , '\ra\r\r' , ' a ' , '\t\t\ta' , 'a\f\f\f' , '\ta\r \n\f' ,
37+ ] . forEach ( ( value ) =>
38+ // See #2 - https://html.spec.whatwg.org/multipage/webappapis.html#dom-atob
39+ throws ( ( ) => atob ( value ) , {
40+ constructor : DOMException ,
41+ name : 'InvalidCharacterError' ,
42+ code : 5 ,
43+ } ) ) ;
0 commit comments