mirror of https://github.com/tc39/test262.git
[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}
This commit is contained in:
parent
b0f03cb22d
commit
701b220976
|
@ -0,0 +1,55 @@
|
|||
// Copyright (C) 2025 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-uint8array.frombase64
|
||||
description: >
|
||||
Uint8Array.fromBase64 throws a TypeError when alphabet and
|
||||
lastChunkHandling are invalid string values.
|
||||
includes: [compareArray.js]
|
||||
features: [uint8array-base64, TypedArray]
|
||||
---*/
|
||||
|
||||
let string = 'SGVsbG8gV29ybGQ=';
|
||||
assert.compareArray(
|
||||
Uint8Array.fromBase64(string),
|
||||
[72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100])
|
||||
|
||||
// invalid alphabet -----
|
||||
|
||||
// shorter length
|
||||
assert.throws(TypeError, function() {
|
||||
Uint8Array.fromBase64(string, {alphabet: 'base'});
|
||||
});
|
||||
// same length but invalid value
|
||||
assert.throws(TypeError, function() {
|
||||
Uint8Array.fromBase64(string, {alphabet: 'base65'});
|
||||
});
|
||||
// longer length
|
||||
assert.throws(TypeError, function() {
|
||||
Uint8Array.fromBase64(string, {alphabet: 'base64urlurl'});
|
||||
});
|
||||
// invalid two-byte value
|
||||
assert.throws(TypeError, function() {
|
||||
Uint8Array.fromBase64(string, {alphabet: '☉‿⊙'});
|
||||
});
|
||||
|
||||
// invalid lastChunkHandling -----
|
||||
|
||||
// shorter length
|
||||
assert.throws(TypeError, function() {
|
||||
Uint8Array.fromBase64(string, {lastChunkHandling: 'stric'});
|
||||
});
|
||||
// same length but invalid value
|
||||
assert.throws(TypeError, function() {
|
||||
Uint8Array.fromBase64(string, {lastChunkHandling: 'looss'});
|
||||
});
|
||||
// longer length
|
||||
assert.throws(TypeError, function() {
|
||||
Uint8Array.fromBase64(
|
||||
string, {lastChunkHandling: 'stop-before-partial-partial'});
|
||||
});
|
||||
// invalid two-byte value
|
||||
assert.throws(TypeError, function() {
|
||||
Uint8Array.fromBase64(string, {lastChunkHandling: '☉‿⊙'});
|
||||
});
|
Loading…
Reference in New Issue