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: Uint8Array.fromBase64 triggers effects of the "alphabet" and "lastChunkHandling" getters, but does not perform toString on the results
7 includes: [compareArray.js]
8 features: [uint8array-base64, TypedArray]
11 assert.throws(TypeError, function() {
12 Uint8Array.fromBase64("Zg==", { alphabet: Object("base64") });
15 assert.throws(TypeError, function() {
16 Uint8Array.fromBase64("Zg==", { lastChunkHandling: Object("loose") });
20 var toStringCalls = 0;
21 var throwyToString = {
22 toString: function() {
24 throw new Test262Error("toString called");
27 assert.throws(TypeError, function() {
28 Uint8Array.fromBase64("Zg==", { alphabet: throwyToString });
30 assert.sameValue(toStringCalls, 0);
32 assert.throws(TypeError, function() {
33 Uint8Array.fromBase64("Zg==", { lastChunkHandling: throwyToString });
35 assert.sameValue(toStringCalls, 0);
38 var alphabetAccesses = 0;
39 var base64UrlOptions = {};
40 Object.defineProperty(base64UrlOptions, "alphabet", {
42 alphabetAccesses += 1;
46 var arr = Uint8Array.fromBase64("x-_y", base64UrlOptions);
47 assert.compareArray(arr, [199, 239, 242]);
48 assert.sameValue(alphabetAccesses, 1);
50 var lastChunkHandlingAccesses = 0;
51 var strictOptions = {};
52 Object.defineProperty(strictOptions, "lastChunkHandling", {
54 lastChunkHandlingAccesses += 1;
58 var arr = Uint8Array.fromBase64("Zg==", strictOptions);
59 assert.compareArray(arr, [102]);
60 assert.sameValue(lastChunkHandlingAccesses, 1);