| 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: 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] |
| 9 |
---*/ |
| 10 |
|
| 11 |
assert.throws(TypeError, function() { |
| 12 |
Uint8Array.fromBase64("Zg==", { alphabet: Object("base64") }); |
| 13 |
}); |
| 14 |
|
| 15 |
assert.throws(TypeError, function() { |
| 16 |
Uint8Array.fromBase64("Zg==", { lastChunkHandling: Object("loose") }); |
| 17 |
}); |
| 18 |
|
| 19 |
|
| 20 |
var toStringCalls = 0; |
| 21 |
var throwyToString = { |
| 22 |
toString: function() { |
| 23 |
toStringCalls += 1; |
| 24 |
throw new Test262Error("toString called"); |
| 25 |
} |
| 26 |
}; |
| 27 |
assert.throws(TypeError, function() { |
| 28 |
Uint8Array.fromBase64("Zg==", { alphabet: throwyToString }); |
| 29 |
}); |
| 30 |
assert.sameValue(toStringCalls, 0); |
| 31 |
|
| 32 |
assert.throws(TypeError, function() { |
| 33 |
Uint8Array.fromBase64("Zg==", { lastChunkHandling: throwyToString }); |
| 34 |
}); |
| 35 |
assert.sameValue(toStringCalls, 0); |
| 36 |
|
| 37 |
|
| 38 |
var alphabetAccesses = 0; |
| 39 |
var base64UrlOptions = {}; |
| 40 |
Object.defineProperty(base64UrlOptions, "alphabet", { |
| 41 |
get: function() { |
| 42 |
alphabetAccesses += 1; |
| 43 |
return "base64url"; |
| 44 |
} |
| 45 |
}); |
| 46 |
var arr = Uint8Array.fromBase64("x-_y", base64UrlOptions); |
| 47 |
assert.compareArray(arr, [199, 239, 242]); |
| 48 |
assert.sameValue(alphabetAccesses, 1); |
| 49 |
|
| 50 |
var lastChunkHandlingAccesses = 0; |
| 51 |
var strictOptions = {}; |
| 52 |
Object.defineProperty(strictOptions, "lastChunkHandling", { |
| 53 |
get: function() { |
| 54 |
lastChunkHandlingAccesses += 1; |
| 55 |
return "strict"; |
| 56 |
} |
| 57 |
}); |
| 58 |
var arr = Uint8Array.fromBase64("Zg==", strictOptions); |
| 59 |
assert.compareArray(arr, [102]); |
| 60 |
assert.sameValue(lastChunkHandlingAccesses, 1); |
| 61 |
|
| 62 |
reportCompare(0, 0); |