1'use strict'; 2 3require('../common'); 4 5const { strictEqual, throws } = require('assert'); 6const buffer = require('buffer'); 7 8// Exported on the global object 9strictEqual(globalThis.atob, buffer.atob); 10strictEqual(globalThis.btoa, buffer.btoa); 11 12// Throws type error on no argument passed 13throws(() => buffer.atob(), /TypeError/); 14throws(() => buffer.btoa(), /TypeError/); 15 16strictEqual(atob(' '), ''); 17strictEqual(atob(' Y\fW\tJ\njZ A=\r= '), 'abcd'); 18 19strictEqual(atob(null), '\x9Eée'); 20strictEqual(atob(NaN), '5£'); 21strictEqual(atob(Infinity), '"wâ\x9E+r'); 22strictEqual(atob(true), '¶»\x9E'); 23strictEqual(atob(1234), '×mø'); 24strictEqual(atob([]), ''); 25strictEqual(atob({ toString: () => '' }), ''); 26strictEqual(atob({ [Symbol.toPrimitive]: () => '' }), ''); 27 28throws(() => atob(Symbol()), /TypeError/); 29[ 30 undefined, false, () => {}, {}, [1], 31 0, 1, 0n, 1n, -Infinity, 32 'a', 'a\n\n\n', '\ra\r\r', ' a ', '\t\t\ta', 'a\f\f\f', '\ta\r \n\f', 33].forEach((value) => 34 // See #2 - https://html.spec.whatwg.org/multipage/webappapis.html#dom-atob 35 throws(() => atob(value), { 36 constructor: DOMException, 37 name: 'InvalidCharacterError', 38 code: 5, 39 })); 40