Debian Codegraph @

js/src/tests/test262/built-ins/Uint8Array/fromBase64/alphabet.js

raw
1 // |reftest| shell-option(--enable-uint8array-base64) skip-if(!Uint8Array.fromBase64||!xulRuntime.shell) -- uint8array-base64 is not enabled unconditionally, requires shell-options
2 // Copyright (C) 2024 Kevin Gibbons. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 esid: sec-uint8array.frombase64
6 description: Conversion of base64 strings to Uint8Arrays exercising the alphabet option
7 includes: [compareArray.js]
8 features: [uint8array-base64, TypedArray]
9 ---*/
10
11 assert.compareArray(Uint8Array.fromBase64('x+/y'), [199, 239, 242]);
12 assert.compareArray(Uint8Array.fromBase64('x+/y', { alphabet: 'base64' }), [199, 239, 242]);
13 assert.throws(SyntaxError, function() {
14 Uint8Array.fromBase64('x+/y', { alphabet: 'base64url' });
15 });
16
17 assert.compareArray(Uint8Array.fromBase64('x-_y', { alphabet: 'base64url' }), [199, 239, 242]);
18 assert.throws(SyntaxError, function() {
19 Uint8Array.fromBase64('x-_y');
20 });
21 assert.throws(SyntaxError, function() {
22 Uint8Array.fromBase64('x-_y', { alphabet: 'base64' });
23 });
24
25 reportCompare(0, 0);