11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_cirequire('../common');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst { strictEqual, throws } = require('assert');
61cb0ef41Sopenharmony_ciconst buffer = require('buffer');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci// Exported on the global object
91cb0ef41Sopenharmony_cistrictEqual(globalThis.atob, buffer.atob);
101cb0ef41Sopenharmony_cistrictEqual(globalThis.btoa, buffer.btoa);
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci// Throws type error on no argument passed
131cb0ef41Sopenharmony_cithrows(() => buffer.atob(), /TypeError/);
141cb0ef41Sopenharmony_cithrows(() => buffer.btoa(), /TypeError/);
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_cistrictEqual(atob(' '), '');
171cb0ef41Sopenharmony_cistrictEqual(atob('  Y\fW\tJ\njZ A=\r= '), 'abcd');
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cistrictEqual(atob(null), '\x9Eée');
201cb0ef41Sopenharmony_cistrictEqual(atob(NaN), '5£');
211cb0ef41Sopenharmony_cistrictEqual(atob(Infinity), '"wâ\x9E+r');
221cb0ef41Sopenharmony_cistrictEqual(atob(true), '¶»\x9E');
231cb0ef41Sopenharmony_cistrictEqual(atob(1234), '×mø');
241cb0ef41Sopenharmony_cistrictEqual(atob([]), '');
251cb0ef41Sopenharmony_cistrictEqual(atob({ toString: () => '' }), '');
261cb0ef41Sopenharmony_cistrictEqual(atob({ [Symbol.toPrimitive]: () => '' }), '');
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_cithrows(() => atob(Symbol()), /TypeError/);
291cb0ef41Sopenharmony_ci[
301cb0ef41Sopenharmony_ci  undefined, false, () => {}, {}, [1],
311cb0ef41Sopenharmony_ci  0, 1, 0n, 1n, -Infinity,
321cb0ef41Sopenharmony_ci  'a', 'a\n\n\n', '\ra\r\r', '  a ', '\t\t\ta', 'a\f\f\f', '\ta\r \n\f',
331cb0ef41Sopenharmony_ci].forEach((value) =>
341cb0ef41Sopenharmony_ci  // See #2 - https://html.spec.whatwg.org/multipage/webappapis.html#dom-atob
351cb0ef41Sopenharmony_ci  throws(() => atob(value), {
361cb0ef41Sopenharmony_ci    constructor: DOMException,
371cb0ef41Sopenharmony_ci    name: 'InvalidCharacterError',
381cb0ef41Sopenharmony_ci    code: 5,
391cb0ef41Sopenharmony_ci  }));
40