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.prototype.setfrombase64
6 description: Conversion of base64 strings to Uint8Arrays exercising the alphabet option
7 includes: [compareArray.js]
8 features: [uint8array-base64, TypedArray]
11 var target = new Uint8Array([255, 255, 255, 255]);
12 var result = target.setFromBase64('x+/y');
13 assert.sameValue(result.read, 4);
14 assert.sameValue(result.written, 3);
15 assert.compareArray(target, [199, 239, 242, 255]);
17 var target = new Uint8Array([255, 255, 255, 255]);
18 var result = target.setFromBase64('x+/y', { alphabet: 'base64' });
19 assert.sameValue(result.read, 4);
20 assert.sameValue(result.written, 3);
21 assert.compareArray(target, [199, 239, 242, 255]);
23 assert.throws(SyntaxError, function() {
24 var target = new Uint8Array([255, 255, 255, 255]);
25 target.setFromBase64('x+/y', { alphabet: 'base64url' });
29 var target = new Uint8Array([255, 255, 255, 255]);
30 var result = target.setFromBase64('x-_y', { alphabet: 'base64url' });
31 assert.sameValue(result.read, 4);
32 assert.sameValue(result.written, 3);
33 assert.compareArray(target, [199, 239, 242, 255]);
35 assert.throws(SyntaxError, function() {
36 var target = new Uint8Array([255, 255, 255, 255]);
37 target.setFromBase64('x-_y');
39 assert.throws(SyntaxError, function() {
40 var target = new Uint8Array([255, 255, 255, 255]);
41 target.setFromBase64('x-_y', { alphabet: 'base64' });