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.
5 esid: sec-uint8array.frombase64
6 description: Handling of final chunks in Uint8Array.fromBase64
7 includes: [compareArray.js]
8 features: [uint8array-base64, TypedArray]
12 assert.compareArray(Uint8Array.fromBase64('ZXhhZg=='), [101, 120, 97, 102]);
13 assert.compareArray(Uint8Array.fromBase64('ZXhhZg==', { lastChunkHandling: 'loose' }), [101, 120, 97, 102]);
14 assert.compareArray(Uint8Array.fromBase64('ZXhhZg==', { lastChunkHandling: 'stop-before-partial' }), [101, 120, 97, 102]);
15 assert.compareArray(Uint8Array.fromBase64('ZXhhZg==', { lastChunkHandling: 'strict' }), [101, 120, 97, 102]);
18 assert.compareArray(Uint8Array.fromBase64('ZXhhZg'), [101, 120, 97, 102]);
19 assert.compareArray(Uint8Array.fromBase64('ZXhhZg', { lastChunkHandling: 'loose' }), [101, 120, 97, 102]);
20 assert.compareArray(Uint8Array.fromBase64('ZXhhZg', { lastChunkHandling: 'stop-before-partial' }), [101, 120, 97]);
21 assert.throws(SyntaxError, function() {
22 Uint8Array.fromBase64('ZXhhZg', { lastChunkHandling: 'strict' });
25 // non-zero padding bits
26 assert.compareArray(Uint8Array.fromBase64('ZXhhZh=='), [101, 120, 97, 102]);
27 assert.compareArray(Uint8Array.fromBase64('ZXhhZh==', { lastChunkHandling: 'loose' }), [101, 120, 97, 102]);
28 assert.compareArray(Uint8Array.fromBase64('ZXhhZh==', { lastChunkHandling: 'stop-before-partial' }), [101, 120, 97, 102]);
29 assert.throws(SyntaxError, function() {
30 Uint8Array.fromBase64('ZXhhZh==', { lastChunkHandling: 'strict' });
33 // non-zero padding bits, no padding
34 assert.compareArray(Uint8Array.fromBase64('ZXhhZh'), [101, 120, 97, 102]);
35 assert.compareArray(Uint8Array.fromBase64('ZXhhZh', { lastChunkHandling: 'loose' }), [101, 120, 97, 102]);
36 assert.compareArray(Uint8Array.fromBase64('ZXhhZh', { lastChunkHandling: 'stop-before-partial' }), [101, 120, 97]);
37 assert.throws(SyntaxError, function() {
38 Uint8Array.fromBase64('ZXhhZh', { lastChunkHandling: 'strict' });
42 assert.throws(SyntaxError, function() {
43 Uint8Array.fromBase64('ZXhhZg=');
45 assert.throws(SyntaxError, function() {
46 Uint8Array.fromBase64('ZXhhZg=', { lastChunkHandling: 'loose' });
48 assert.compareArray(Uint8Array.fromBase64('ZXhhZg=', { lastChunkHandling: 'stop-before-partial' }), [101, 120, 97]);
49 assert.throws(SyntaxError, function() {
50 Uint8Array.fromBase64('ZXhhZg=', { lastChunkHandling: 'strict' });
54 assert.throws(SyntaxError, function() {
55 Uint8Array.fromBase64('ZXhhZg===');
57 assert.throws(SyntaxError, function() {
58 Uint8Array.fromBase64('ZXhhZg===', { lastChunkHandling: 'loose' });
60 assert.throws(SyntaxError, function() {
61 Uint8Array.fromBase64('ZXhhZg===', { lastChunkHandling: 'stop-before-partial' });
63 assert.throws(SyntaxError, function() {
64 Uint8Array.fromBase64('ZXhhZg===', { lastChunkHandling: 'strict' });