Skip to content

Commit 701b220

Browse files
rmahdavtest262-merge-bot
authored andcommitted
[base64] Add FromBase64
This CL adds `Uint8Array.fromBase64()`. Bug: 42204568 Change-Id: Ib68683a2d5ead9720077197c0f895787214b183e Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6026354 Commit-Queue: Rezvan Mahdavi Hezaveh <rezvan@chromium.org> Reviewed-by: Shu-yu Guo <syg@chromium.org> Cr-Commit-Position: refs/heads/main@{#98239}
1 parent b0f03cb commit 701b220

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (C) 2025 the V8 project authors. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-uint8array.frombase64
6+
description: >
7+
Uint8Array.fromBase64 throws a TypeError when alphabet and
8+
lastChunkHandling are invalid string values.
9+
includes: [compareArray.js]
10+
features: [uint8array-base64, TypedArray]
11+
---*/
12+
13+
let string = 'SGVsbG8gV29ybGQ=';
14+
assert.compareArray(
15+
Uint8Array.fromBase64(string),
16+
[72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100])
17+
18+
// invalid alphabet -----
19+
20+
// shorter length
21+
assert.throws(TypeError, function() {
22+
Uint8Array.fromBase64(string, {alphabet: 'base'});
23+
});
24+
// same length but invalid value
25+
assert.throws(TypeError, function() {
26+
Uint8Array.fromBase64(string, {alphabet: 'base65'});
27+
});
28+
// longer length
29+
assert.throws(TypeError, function() {
30+
Uint8Array.fromBase64(string, {alphabet: 'base64urlurl'});
31+
});
32+
// invalid two-byte value
33+
assert.throws(TypeError, function() {
34+
Uint8Array.fromBase64(string, {alphabet: '☉‿⊙'});
35+
});
36+
37+
// invalid lastChunkHandling -----
38+
39+
// shorter length
40+
assert.throws(TypeError, function() {
41+
Uint8Array.fromBase64(string, {lastChunkHandling: 'stric'});
42+
});
43+
// same length but invalid value
44+
assert.throws(TypeError, function() {
45+
Uint8Array.fromBase64(string, {lastChunkHandling: 'looss'});
46+
});
47+
// longer length
48+
assert.throws(TypeError, function() {
49+
Uint8Array.fromBase64(
50+
string, {lastChunkHandling: 'stop-before-partial-partial'});
51+
});
52+
// invalid two-byte value
53+
assert.throws(TypeError, function() {
54+
Uint8Array.fromBase64(string, {lastChunkHandling: '☉‿⊙'});
55+
});

0 commit comments

Comments
 (0)