|
| 1 | +// Copyright (C) 2025 Richard Gibson. All rights reserved. |
| 2 | +// This code is governed by the BSD license found in the LICENSE file. |
| 3 | + |
| 4 | +/*--- |
| 5 | +esid: sec-uint8array.prototype.setfrombase64 |
| 6 | +description: Throws a TypeError exception when the backing buffer is immutable |
| 7 | +info: | |
| 8 | + Uint8Array.prototype.setFromBase64 ( string [ , options ] ) |
| 9 | + 1. Let into be the this value. |
| 10 | + 2. Perform ? ValidateUint8Array(into). |
| 11 | + 3. If string is not a String, throw a TypeError exception. |
| 12 | + 4. Let opts be ? GetOptionsObject(options). |
| 13 | + 5. Let alphabet be ? Get(opts, "alphabet"). |
| 14 | + 6. If alphabet is undefined, set alphabet to "base64". |
| 15 | + 7. If alphabet is neither "base64" nor "base64url", throw a TypeError exception. |
| 16 | + 8. Let lastChunkHandling be ? Get(opts, "lastChunkHandling"). |
| 17 | +features: [TypedArray, uint8array-base64, immutable-arraybuffer] |
| 18 | +includes: [testTypedArray.js, compareArray.js] |
| 19 | +---*/ |
| 20 | + |
| 21 | +testWithAllTypedArrayConstructors((TA, makeCtorArg) => { |
| 22 | + var calls = []; |
| 23 | + |
| 24 | + var ta = new TA(makeCtorArg(["1", "2", "3", "4"])); |
| 25 | + var options = { |
| 26 | + get alphabet() { |
| 27 | + calls.push("get options.alphabet"); |
| 28 | + return undefined; |
| 29 | + }, |
| 30 | + get lastChunkHandling() { |
| 31 | + calls.push("get options.lastChunkHandling"); |
| 32 | + return undefined; |
| 33 | + }, |
| 34 | + }; |
| 35 | + |
| 36 | + assert.throws(TypeError, function() { |
| 37 | + ta.setFromBase64("Zm9v", options); |
| 38 | + }); |
| 39 | + assert.compareArray(calls, [], "Must verify mutability before reading arguments."); |
| 40 | + assert.compareArray(ta, new TA(["1", "2", "3", "4"]), "Must not mutate contents."); |
| 41 | +}, [Uint8Array], ["immutable"]); |
0 commit comments