1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// |reftest| shell-option(--enable-uint8array-base64) skip-if(!Uint8Array.fromBase64||!xulRuntime.shell) -- uint8array-base64 is not enabled unconditionally, requires shell-options
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-uint8array.prototype.setfrombase64
description: Uint8Array.prototype.setFromBase64 triggers effects of the "alphabet" and "lastChunkHandling" getters, but does not perform toString on the results
includes: [compareArray.js]
features: [uint8array-base64, TypedArray]
---*/
assert.throws(TypeError, function() {
var target = new Uint8Array([255, 255, 255]);
target.setFromBase64("Zg==", { alphabet: Object("base64") });
});
assert.throws(TypeError, function() {
var target = new Uint8Array([255, 255, 255]);
target.setFromBase64("Zg==", { lastChunkHandling: Object("strict") });
});
var toStringCalls = 0;
var throwyToString = {
toString: function() {
toStringCalls += 1;
throw new Test262Error("toString called");
}
};
assert.throws(TypeError, function() {
var target = new Uint8Array([255, 255, 255]);
target.setFromBase64("Zg==", { alphabet: throwyToString });
});
assert.sameValue(toStringCalls, 0);
assert.throws(TypeError, function() {
var target = new Uint8Array([255, 255, 255]);
target.setFromBase64("Zg==", { lastChunkHandling: throwyToString });
});
assert.sameValue(toStringCalls, 0);
var alphabetAccesses = 0;
var base64UrlOptions = {};
Object.defineProperty(base64UrlOptions, "alphabet", {
get: function() {
alphabetAccesses += 1;
return "base64url";
}
});
var target = new Uint8Array([255, 255, 255, 255]);
var result = target.setFromBase64("x-_y", base64UrlOptions);
assert.sameValue(result.read, 4);
assert.sameValue(result.written, 3);
assert.compareArray(target, [199, 239, 242, 255]);
assert.sameValue(alphabetAccesses, 1);
var lastChunkHandlingAccesses = 0;
var strictOptions = {};
Object.defineProperty(strictOptions, "lastChunkHandling", {
get: function() {
lastChunkHandlingAccesses += 1;
return "strict";
}
});
var target = new Uint8Array([255, 255, 255, 255]);
var result = target.setFromBase64("Zg==", strictOptions);
assert.sameValue(result.read, 4);
assert.sameValue(result.written, 1);
assert.compareArray(target, [102, 255, 255, 255]);
assert.sameValue(lastChunkHandlingAccesses, 1);
reportCompare(0, 0);
|