mirror of
https://github.com/tc39/test262.git
synced 2025-05-25 17:20:41 +02:00
add tests for base64 proposal
This commit is contained in:
parent
3a7a72aef5
commit
bd05e23d40
@ -131,6 +131,10 @@ source-phase-imports
|
|||||||
## test262 special specifier
|
## test262 special specifier
|
||||||
source-phase-imports-module-source
|
source-phase-imports-module-source
|
||||||
|
|
||||||
|
# Uint8Array Base64
|
||||||
|
# https://github.com/tc39/proposal-arraybuffer-base64
|
||||||
|
uint8array-base64
|
||||||
|
|
||||||
## Standard language features
|
## Standard language features
|
||||||
#
|
#
|
||||||
# Language features that have been included in a published version of the
|
# Language features that have been included in a published version of the
|
||||||
|
22
test/built-ins/Uint8Array/fromBase64/alphabet.js
Normal file
22
test/built-ins/Uint8Array/fromBase64/alphabet.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64
|
||||||
|
description: Conversion of base64 strings to Uint8Arrays exercising the alphabet option
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.compareArray(Uint8Array.fromBase64('x+/y'), [199, 239, 242]);
|
||||||
|
assert.compareArray(Uint8Array.fromBase64('x+/y', { alphabet: 'base64' }), [199, 239, 242]);
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
Uint8Array.fromBase64('x+/y', { alphabet: 'base64url' });
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.compareArray(Uint8Array.fromBase64('x-_y', { alphabet: 'base64url' }), [199, 239, 242]);
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
Uint8Array.fromBase64('x-_y');
|
||||||
|
});
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
Uint8Array.fromBase64('x-_y', { alphabet: 'base64' });
|
||||||
|
});
|
15
test/built-ins/Uint8Array/fromBase64/descriptor.js
Normal file
15
test/built-ins/Uint8Array/fromBase64/descriptor.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64
|
||||||
|
description: >
|
||||||
|
Uint8Array.fromBase64 has default data property attributes.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array, 'fromBase64', {
|
||||||
|
enumerable: false,
|
||||||
|
writable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
19
test/built-ins/Uint8Array/fromBase64/ignores-receiver.js
Normal file
19
test/built-ins/Uint8Array/fromBase64/ignores-receiver.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64
|
||||||
|
description: Uint8Array.fromBase64 ignores its receiver
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var fromBase64 = Uint8Array.fromBase64;
|
||||||
|
var noReceiver = fromBase64("Zg==");
|
||||||
|
assert.sameValue(Object.getPrototypeOf(noReceiver), Uint8Array.prototype);
|
||||||
|
|
||||||
|
class Subclass extends Uint8Array {
|
||||||
|
constructor() {
|
||||||
|
throw new Test262Error("subclass constructor called");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var fromSubclass = Subclass.fromBase64("Zg==");
|
||||||
|
assert.sameValue(Object.getPrototypeOf(fromSubclass), Uint8Array.prototype);
|
23
test/built-ins/Uint8Array/fromBase64/illegal-characters.js
Normal file
23
test/built-ins/Uint8Array/fromBase64/illegal-characters.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. 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 SyntaxError when input has non-base64, non-ascii-whitespace characters
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var illegal = [
|
||||||
|
'Zm.9v',
|
||||||
|
'Zm9v^',
|
||||||
|
'Zg==&',
|
||||||
|
'Z−==', // U+2212 'Minus Sign'
|
||||||
|
'Z+==', // U+FF0B 'Fullwidth Plus Sign'
|
||||||
|
'Zg\u00A0==', // nbsp
|
||||||
|
'Zg\u2009==', // thin space
|
||||||
|
'Zg\u2028==', // line separator
|
||||||
|
];
|
||||||
|
illegal.forEach(function(value) {
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
Uint8Array.fromBase64(value)
|
||||||
|
});
|
||||||
|
});
|
50
test/built-ins/Uint8Array/fromBase64/last-chunk-handling.js
Normal file
50
test/built-ins/Uint8Array/fromBase64/last-chunk-handling.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64
|
||||||
|
description: Handling of final chunks in Uint8Array.fromBase64
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// padding
|
||||||
|
assert.compareArray(Uint8Array.fromBase64('ZXhhZg=='), [101, 120, 97, 102]);
|
||||||
|
assert.compareArray(Uint8Array.fromBase64('ZXhhZg==', { lastChunkHandling: 'loose' }), [101, 120, 97, 102]);
|
||||||
|
assert.compareArray(Uint8Array.fromBase64('ZXhhZg==', { lastChunkHandling: 'stop-before-partial' }), [101, 120, 97, 102]);
|
||||||
|
assert.compareArray(Uint8Array.fromBase64('ZXhhZg==', { lastChunkHandling: 'strict' }), [101, 120, 97, 102]);
|
||||||
|
|
||||||
|
// no padding
|
||||||
|
assert.compareArray(Uint8Array.fromBase64('ZXhhZg'), [101, 120, 97, 102]);
|
||||||
|
assert.compareArray(Uint8Array.fromBase64('ZXhhZg', { lastChunkHandling: 'loose' }), [101, 120, 97, 102]);
|
||||||
|
assert.compareArray(Uint8Array.fromBase64('ZXhhZg', { lastChunkHandling: 'stop-before-partial' }), [101, 120, 97]);
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
Uint8Array.fromBase64('ZXhhZg', { lastChunkHandling: 'strict' });
|
||||||
|
});
|
||||||
|
|
||||||
|
// non-zero padding bits
|
||||||
|
assert.compareArray(Uint8Array.fromBase64('ZXhhZh=='), [101, 120, 97, 102]);
|
||||||
|
assert.compareArray(Uint8Array.fromBase64('ZXhhZh==', { lastChunkHandling: 'loose' }), [101, 120, 97, 102]);
|
||||||
|
assert.compareArray(Uint8Array.fromBase64('ZXhhZh==', { lastChunkHandling: 'stop-before-partial' }), [101, 120, 97, 102]);
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
Uint8Array.fromBase64('ZXhhZh==', { lastChunkHandling: 'strict' });
|
||||||
|
});
|
||||||
|
|
||||||
|
// non-zero padding bits, no padding
|
||||||
|
assert.compareArray(Uint8Array.fromBase64('ZXhhZh'), [101, 120, 97, 102]);
|
||||||
|
assert.compareArray(Uint8Array.fromBase64('ZXhhZh', { lastChunkHandling: 'loose' }), [101, 120, 97, 102]);
|
||||||
|
assert.compareArray(Uint8Array.fromBase64('ZXhhZh', { lastChunkHandling: 'stop-before-partial' }), [101, 120, 97]);
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
Uint8Array.fromBase64('ZXhhZh', { lastChunkHandling: 'strict' });
|
||||||
|
});
|
||||||
|
|
||||||
|
// malformed padding
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
Uint8Array.fromBase64('ZXhhZg=');
|
||||||
|
});
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
Uint8Array.fromBase64('ZXhhZg=', { lastChunkHandling: 'loose' });
|
||||||
|
});
|
||||||
|
assert.compareArray(Uint8Array.fromBase64('ZXhhZg=', { lastChunkHandling: 'stop-before-partial' }), [101, 120, 97]);
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
Uint8Array.fromBase64('ZXhhZg=', { lastChunkHandling: 'strict' });
|
||||||
|
});
|
16
test/built-ins/Uint8Array/fromBase64/length.js
Normal file
16
test/built-ins/Uint8Array/fromBase64/length.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64
|
||||||
|
description: >
|
||||||
|
Uint8Array.fromBase64.length is 1.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array.fromBase64, 'length', {
|
||||||
|
value: 1,
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
16
test/built-ins/Uint8Array/fromBase64/name.js
Normal file
16
test/built-ins/Uint8Array/fromBase64/name.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64
|
||||||
|
description: >
|
||||||
|
Uint8Array.fromBase64.name is "fromBase64".
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array.fromBase64, 'name', {
|
||||||
|
value: 'fromBase64',
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
15
test/built-ins/Uint8Array/fromBase64/nonconstructor.js
Normal file
15
test/built-ins/Uint8Array/fromBase64/nonconstructor.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64
|
||||||
|
description: >
|
||||||
|
Uint8Array.fromBase64 is not a constructor function.
|
||||||
|
includes: [isConstructor.js]
|
||||||
|
features: [uint8array-base64, Reflect.construct]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert(!isConstructor(Uint8Array.fromBase64), "Uint8Array.fromBase64 is not a constructor");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
new Uint8Array.fromBase64('');
|
||||||
|
});
|
50
test/built-ins/Uint8Array/fromBase64/option-coercion.js
Normal file
50
test/built-ins/Uint8Array/fromBase64/option-coercion.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64
|
||||||
|
description: Uint8Array.fromBase64 triggers effects of the "alphabet" and "lastChunkHandling" getters, but does not perform toString on the results
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var toStringCalls = 0;
|
||||||
|
var throwyToString = {
|
||||||
|
toString: function() {
|
||||||
|
toStringCalls += 1;
|
||||||
|
throw new Test262Error("toString called");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Uint8Array.fromBase64("Zg==", { alphabet: throwyToString });
|
||||||
|
});
|
||||||
|
assert.sameValue(toStringCalls, 0);
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Uint8Array.fromBase64("Zg==", { lastChunkHandling: throwyToString });
|
||||||
|
});
|
||||||
|
assert.sameValue(toStringCalls, 0);
|
||||||
|
|
||||||
|
|
||||||
|
var alphabetAccesses = 0;
|
||||||
|
var base64UrlOptions = {};
|
||||||
|
Object.defineProperty(base64UrlOptions, "alphabet", {
|
||||||
|
get: function() {
|
||||||
|
alphabetAccesses += 1;
|
||||||
|
return "base64url";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var arr = Uint8Array.fromBase64("x-_y", base64UrlOptions);
|
||||||
|
assert.compareArray(arr, [199, 239, 242]);
|
||||||
|
assert.sameValue(alphabetAccesses, 1);
|
||||||
|
|
||||||
|
var lastChunkHandlingAccesses = 0;
|
||||||
|
var strictOptions = {};
|
||||||
|
Object.defineProperty(strictOptions, "lastChunkHandling", {
|
||||||
|
get: function() {
|
||||||
|
lastChunkHandlingAccesses += 1;
|
||||||
|
return "strict";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var arr = Uint8Array.fromBase64("Zg==", strictOptions);
|
||||||
|
assert.compareArray(arr, [102]);
|
||||||
|
assert.sameValue(lastChunkHandlingAccesses, 1);
|
25
test/built-ins/Uint8Array/fromBase64/results.js
Normal file
25
test/built-ins/Uint8Array/fromBase64/results.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64
|
||||||
|
description: Conversion of base64 strings to Uint8Arrays
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// standard test vectors from https://datatracker.ietf.org/doc/html/rfc4648#section-10
|
||||||
|
var standardBase64Vectors = [
|
||||||
|
["", []],
|
||||||
|
["Zg==", [102]],
|
||||||
|
["Zm8=", [102, 111]],
|
||||||
|
["Zm9v", [102, 111, 111]],
|
||||||
|
["Zm9vYg==", [102, 111, 111, 98]],
|
||||||
|
["Zm9vYmE=", [102, 111, 111, 98, 97]],
|
||||||
|
["Zm9vYmFy", [102, 111, 111, 98, 97, 114]],
|
||||||
|
];
|
||||||
|
|
||||||
|
standardBase64Vectors.forEach(function (pair) {
|
||||||
|
var arr = Uint8Array.fromBase64(pair[0]);
|
||||||
|
assert.sameValue(Object.getPrototypeOf(arr), Uint8Array.prototype, "decoding " + pair[0]);
|
||||||
|
assert.compareArray(arr, pair[1], "decoding " + pair[0]);
|
||||||
|
});
|
41
test/built-ins/Uint8Array/fromBase64/string-coercion.js
Normal file
41
test/built-ins/Uint8Array/fromBase64/string-coercion.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64
|
||||||
|
description: Uint8Array.fromBase64 throws if its argument is not a string
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var toStringCalls = 0;
|
||||||
|
var throwyToString = {
|
||||||
|
toString: function() {
|
||||||
|
toStringCalls += 1;
|
||||||
|
throw new Test262Error("toString called");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Uint8Array.fromBase64(throwyToString);
|
||||||
|
});
|
||||||
|
assert.sameValue(toStringCalls, 0);
|
||||||
|
|
||||||
|
|
||||||
|
var optionAccesses = 0;
|
||||||
|
var touchyOptions = {};
|
||||||
|
Object.defineProperty(touchyOptions, "alphabet", {
|
||||||
|
get: function() {
|
||||||
|
optionAccesses += 1;
|
||||||
|
throw new Test262Error("alphabet accessed");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Object.defineProperty(touchyOptions, "lastChunkHandling", {
|
||||||
|
get: function() {
|
||||||
|
optionAccesses += 1;
|
||||||
|
throw new Test262Error("lastChunkHandling accessed");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Uint8Array.fromBase64(throwyToString, touchyOptions);
|
||||||
|
});
|
||||||
|
assert.sameValue(toStringCalls, 0);
|
||||||
|
assert.sameValue(optionAccesses, 0);
|
20
test/built-ins/Uint8Array/fromBase64/whitespace.js
Normal file
20
test/built-ins/Uint8Array/fromBase64/whitespace.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64
|
||||||
|
description: Uint8Array.fromBase64 ignores ASCII whitespace in the input
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var whitespaceKinds = [
|
||||||
|
["Z g==", "space"],
|
||||||
|
["Z\tg==", "tab"],
|
||||||
|
["Z\x0Ag==", "LF"],
|
||||||
|
["Z\x0Cg==", "FF"],
|
||||||
|
["Z\x0Dg==", "CR"],
|
||||||
|
];
|
||||||
|
whitespaceKinds.forEach(function(pair) {
|
||||||
|
var arr = Uint8Array.fromBase64(pair[0]);
|
||||||
|
assert.compareArray(arr, [102], "ascii whitespace: " + pair[1]);
|
||||||
|
});
|
41
test/built-ins/Uint8Array/fromBase64Into/alphabet.js
Normal file
41
test/built-ins/Uint8Array/fromBase64Into/alphabet.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64into
|
||||||
|
description: Conversion of base64 strings to Uint8Arrays exercising the alphabet option
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('x+/y', target);
|
||||||
|
assert.sameValue(result.read, 4);
|
||||||
|
assert.sameValue(result.written, 3);
|
||||||
|
assert.compareArray(target, [199, 239, 242, 255]);
|
||||||
|
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('x+/y', target, { alphabet: 'base64' });
|
||||||
|
assert.sameValue(result.read, 4);
|
||||||
|
assert.sameValue(result.written, 3);
|
||||||
|
assert.compareArray(target, [199, 239, 242, 255]);
|
||||||
|
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255]);
|
||||||
|
Uint8Array.fromBase64('x+/y', { alphabet: 'base64url' });
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('x-_y', target, { alphabet: 'base64url' });
|
||||||
|
assert.sameValue(result.read, 4);
|
||||||
|
assert.sameValue(result.written, 3);
|
||||||
|
assert.compareArray(target, [199, 239, 242, 255]);
|
||||||
|
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255]);
|
||||||
|
Uint8Array.fromBase64('x-_y');
|
||||||
|
});
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255]);
|
||||||
|
Uint8Array.fromBase64('x-_y', { alphabet: 'base64' });
|
||||||
|
});
|
15
test/built-ins/Uint8Array/fromBase64Into/descriptor.js
Normal file
15
test/built-ins/Uint8Array/fromBase64Into/descriptor.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64into
|
||||||
|
description: >
|
||||||
|
Uint8Array.fromBase64Into has default data property attributes.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array, 'fromBase64Into', {
|
||||||
|
enumerable: false,
|
||||||
|
writable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
29
test/built-ins/Uint8Array/fromBase64Into/detached-buffer.js
Normal file
29
test/built-ins/Uint8Array/fromBase64Into/detached-buffer.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64into
|
||||||
|
description: Uint8Array.fromBase64Into does not write to or error on detatched buffers
|
||||||
|
includes: [detachArrayBuffer.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var target = new Uint8Array([255, 255, 255]);
|
||||||
|
$DETACHBUFFER(target.buffer);
|
||||||
|
var result = Uint8Array.fromBase64Into('Zg==', target);
|
||||||
|
assert.sameValue(result.read, 0);
|
||||||
|
assert.sameValue(result.written, 0);
|
||||||
|
|
||||||
|
var getterCalls = 0;
|
||||||
|
var targetDetachingOptions = {};
|
||||||
|
Object.defineProperty(targetDetachingOptions, 'alphabet', {
|
||||||
|
get: function() {
|
||||||
|
getterCalls += 1;
|
||||||
|
$DETACHBUFFER(target.buffer);
|
||||||
|
return "base64";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var target = new Uint8Array([255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('Zg==', target, targetDetachingOptions);
|
||||||
|
assert.sameValue(getterCalls, 1);
|
||||||
|
assert.sameValue(result.read, 0);
|
||||||
|
assert.sameValue(result.written, 0);
|
16
test/built-ins/Uint8Array/fromBase64Into/ignores-receiver.js
Normal file
16
test/built-ins/Uint8Array/fromBase64Into/ignores-receiver.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64into
|
||||||
|
description: Uint8Array.fromBase64Into ignores its receiver
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var fromBase64Into = Uint8Array.fromBase64Into;
|
||||||
|
var target = new Uint8Array([255, 255, 255]);
|
||||||
|
|
||||||
|
var result = fromBase64Into("Zg==", target);
|
||||||
|
assert.sameValue(result.read, 4);
|
||||||
|
assert.sameValue(result.written, 1);
|
||||||
|
assert.compareArray(target, [102, 255, 255]);
|
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64into
|
||||||
|
description: Uint8Array.fromBase64 throws a SyntaxError when input has non-base64, non-ascii-whitespace characters
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var illegal = [
|
||||||
|
'Zm.9v',
|
||||||
|
'Zm9v^',
|
||||||
|
'Zg==&',
|
||||||
|
'Z−==', // U+2212 'Minus Sign'
|
||||||
|
'Z+==', // U+FF0B 'Fullwidth Plus Sign'
|
||||||
|
'Zg\u00A0==', // nbsp
|
||||||
|
'Zg\u2009==', // thin space
|
||||||
|
'Zg\u2028==', // line separator
|
||||||
|
];
|
||||||
|
illegal.forEach(function(value) {
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255]);
|
||||||
|
Uint8Array.fromBase64Into(value, target);
|
||||||
|
});
|
||||||
|
});
|
131
test/built-ins/Uint8Array/fromBase64Into/last-chunk-handling.js
Normal file
131
test/built-ins/Uint8Array/fromBase64Into/last-chunk-handling.js
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64into
|
||||||
|
description: Handling of final chunks in Uint8Array.fromBase64Into
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// padding
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('ZXhhZg==', target);
|
||||||
|
assert.sameValue(result.read, 8);
|
||||||
|
assert.sameValue(result.written, 4);
|
||||||
|
assert.compareArray(target, [101, 120, 97, 102, 255, 255]);
|
||||||
|
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('ZXhhZg==', target, { lastChunkHandling: 'loose' });
|
||||||
|
assert.sameValue(result.read, 8);
|
||||||
|
assert.sameValue(result.written, 4);
|
||||||
|
assert.compareArray(target, [101, 120, 97, 102, 255, 255]);
|
||||||
|
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('ZXhhZg==', target, { lastChunkHandling: 'stop-before-partial' });
|
||||||
|
assert.sameValue(result.read, 8);
|
||||||
|
assert.sameValue(result.written, 4);
|
||||||
|
assert.compareArray(target, [101, 120, 97, 102, 255, 255]);
|
||||||
|
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('ZXhhZg==', target, { lastChunkHandling: 'strict' });
|
||||||
|
assert.sameValue(result.read, 8);
|
||||||
|
assert.sameValue(result.written, 4);
|
||||||
|
assert.compareArray(target, [101, 120, 97, 102, 255, 255]);
|
||||||
|
|
||||||
|
|
||||||
|
// no padding
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('ZXhhZg', target);
|
||||||
|
assert.sameValue(result.read, 6);
|
||||||
|
assert.sameValue(result.written, 4);
|
||||||
|
assert.compareArray(target, [101, 120, 97, 102, 255, 255]);
|
||||||
|
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('ZXhhZg', target, { lastChunkHandling: 'loose' });
|
||||||
|
assert.sameValue(result.read, 6);
|
||||||
|
assert.sameValue(result.written, 4);
|
||||||
|
assert.compareArray(target, [101, 120, 97, 102, 255, 255]);
|
||||||
|
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('ZXhhZg', target, { lastChunkHandling: 'stop-before-partial' });
|
||||||
|
assert.sameValue(result.read, 4);
|
||||||
|
assert.sameValue(result.written, 3);
|
||||||
|
assert.compareArray(target, [101, 120, 97, 255, 255, 255]);
|
||||||
|
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
Uint8Array.fromBase64Into('ZXhhZg', target, { lastChunkHandling: 'strict' });
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// non-zero padding bits
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('ZXhhZh==', target);
|
||||||
|
assert.sameValue(result.read, 8);
|
||||||
|
assert.sameValue(result.written, 4);
|
||||||
|
assert.compareArray(target, [101, 120, 97, 102, 255, 255]);
|
||||||
|
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('ZXhhZh==', target, { lastChunkHandling: 'loose' });
|
||||||
|
assert.sameValue(result.read, 8);
|
||||||
|
assert.sameValue(result.written, 4);
|
||||||
|
assert.compareArray(target, [101, 120, 97, 102, 255, 255]);
|
||||||
|
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('ZXhhZh==', target, { lastChunkHandling: 'stop-before-partial' });
|
||||||
|
assert.sameValue(result.read, 8);
|
||||||
|
assert.sameValue(result.written, 4);
|
||||||
|
assert.compareArray(target, [101, 120, 97, 102, 255, 255]);
|
||||||
|
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
Uint8Array.fromBase64Into('ZXhhZh==', target, { lastChunkHandling: 'strict' });
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// non-zero padding bits, no padding
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('ZXhhZh', target);
|
||||||
|
assert.sameValue(result.read, 6);
|
||||||
|
assert.sameValue(result.written, 4);
|
||||||
|
assert.compareArray(target, [101, 120, 97, 102, 255, 255]);
|
||||||
|
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('ZXhhZh', target, { lastChunkHandling: 'loose' });
|
||||||
|
assert.sameValue(result.read, 6);
|
||||||
|
assert.sameValue(result.written, 4);
|
||||||
|
assert.compareArray(target, [101, 120, 97, 102, 255, 255]);
|
||||||
|
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('ZXhhZh', target, { lastChunkHandling: 'stop-before-partial' });
|
||||||
|
assert.sameValue(result.read, 4);
|
||||||
|
assert.sameValue(result.written, 3);
|
||||||
|
assert.compareArray(target, [101, 120, 97, 255, 255, 255]);
|
||||||
|
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
Uint8Array.fromBase64Into('ZXhhZh', target, { lastChunkHandling: 'strict' });
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// malformed padding
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
Uint8Array.fromBase64Into('ZXhhZg=', target);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
Uint8Array.fromBase64Into('ZXhhZg=', target, { lastChunkHandling: 'loose' });
|
||||||
|
});
|
||||||
|
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('ZXhhZg=', target, { lastChunkHandling: 'stop-before-partial' });
|
||||||
|
assert.sameValue(result.read, 4);
|
||||||
|
assert.sameValue(result.written, 3);
|
||||||
|
assert.compareArray(target, [101, 120, 97, 255, 255, 255]);
|
||||||
|
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
Uint8Array.fromBase64Into('ZXhhZg=', target, { lastChunkHandling: 'strict' });
|
||||||
|
});
|
16
test/built-ins/Uint8Array/fromBase64Into/length.js
Normal file
16
test/built-ins/Uint8Array/fromBase64Into/length.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64into
|
||||||
|
description: >
|
||||||
|
Uint8Array.fromBase64Into.length is 2.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array.fromBase64Into, 'length', {
|
||||||
|
value: 2,
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
16
test/built-ins/Uint8Array/fromBase64Into/name.js
Normal file
16
test/built-ins/Uint8Array/fromBase64Into/name.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64into
|
||||||
|
description: >
|
||||||
|
Uint8Array.fromBase64Into.name is "fromBase64Into".
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array.fromBase64Into, 'name', {
|
||||||
|
value: 'fromBase64Into',
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
16
test/built-ins/Uint8Array/fromBase64Into/nonconstructor.js
Normal file
16
test/built-ins/Uint8Array/fromBase64Into/nonconstructor.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64into
|
||||||
|
description: >
|
||||||
|
Uint8Array.fromBase64Into is not a constructor function.
|
||||||
|
includes: [isConstructor.js]
|
||||||
|
features: [uint8array-base64, Reflect.construct]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert(!isConstructor(Uint8Array.fromBase64Into), "Uint8Array.fromBase64Into is not a constructor");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
var target = new Uint8Array(10);
|
||||||
|
new Uint8Array.fromBase64Into('', target);
|
||||||
|
});
|
58
test/built-ins/Uint8Array/fromBase64Into/option-coercion.js
Normal file
58
test/built-ins/Uint8Array/fromBase64Into/option-coercion.js
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64into
|
||||||
|
description: Uint8Array.fromBase64Into triggers effects of the "alphabet" and "lastChunkHandling" getters, but does not perform toString on the results
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
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]);
|
||||||
|
Uint8Array.fromBase64Into("Zg==", target, { alphabet: throwyToString });
|
||||||
|
});
|
||||||
|
assert.sameValue(toStringCalls, 0);
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
var target = new Uint8Array([255, 255, 255]);
|
||||||
|
Uint8Array.fromBase64Into("Zg==", target, { 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 = Uint8Array.fromBase64Into("x-_y", target, 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 = Uint8Array.fromBase64Into("Zg==", target, strictOptions);
|
||||||
|
assert.sameValue(result.read, 4);
|
||||||
|
assert.sameValue(result.written, 1);
|
||||||
|
assert.compareArray(target, [102, 255, 255, 255]);
|
||||||
|
assert.sameValue(lastChunkHandlingAccesses, 1);
|
30
test/built-ins/Uint8Array/fromBase64Into/results.js
Normal file
30
test/built-ins/Uint8Array/fromBase64Into/results.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64into
|
||||||
|
description: Conversion of base64 strings to Uint8Arrays
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// standard test vectors from https://datatracker.ietf.org/doc/html/rfc4648#section-10
|
||||||
|
var standardBase64Vectors = [
|
||||||
|
["", []],
|
||||||
|
["Zg==", [102]],
|
||||||
|
["Zm8=", [102, 111]],
|
||||||
|
["Zm9v", [102, 111, 111]],
|
||||||
|
["Zm9vYg==", [102, 111, 111, 98]],
|
||||||
|
["Zm9vYmE=", [102, 111, 111, 98, 97]],
|
||||||
|
["Zm9vYmFy", [102, 111, 111, 98, 97, 114]],
|
||||||
|
];
|
||||||
|
|
||||||
|
standardBase64Vectors.forEach(function (pair) {
|
||||||
|
var allFF = [255, 255, 255, 255, 255, 255, 255, 255];
|
||||||
|
var target = new Uint8Array(allFF);
|
||||||
|
var result = Uint8Array.fromBase64Into(pair[0], target);
|
||||||
|
assert.sameValue(result.read, pair[0].length);
|
||||||
|
assert.sameValue(result.written, pair[1].length);
|
||||||
|
|
||||||
|
var expected = pair[1].concat(allFF.slice(pair[1].length))
|
||||||
|
assert.compareArray(target, expected, "decoding " + pair[0]);
|
||||||
|
});
|
43
test/built-ins/Uint8Array/fromBase64Into/string-coercion.js
Normal file
43
test/built-ins/Uint8Array/fromBase64Into/string-coercion.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64into
|
||||||
|
description: Uint8Array.fromBase64Into throws if its first argument is not a string
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var toStringCalls = 0;
|
||||||
|
var throwyToString = {
|
||||||
|
toString: function() {
|
||||||
|
toStringCalls += 1;
|
||||||
|
throw new Test262Error("toString called");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
var target = new Uint8Array(10);
|
||||||
|
Uint8Array.fromBase64Into(throwyToString, target);
|
||||||
|
});
|
||||||
|
assert.sameValue(toStringCalls, 0);
|
||||||
|
|
||||||
|
|
||||||
|
var optionAccesses = 0;
|
||||||
|
var touchyOptions = {};
|
||||||
|
Object.defineProperty(touchyOptions, "alphabet", {
|
||||||
|
get: function() {
|
||||||
|
optionAccesses += 1;
|
||||||
|
throw new Test262Error("alphabet accessed");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Object.defineProperty(touchyOptions, "lastChunkHandling", {
|
||||||
|
get: function() {
|
||||||
|
optionAccesses += 1;
|
||||||
|
throw new Test262Error("lastChunkHandling accessed");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
var target = new Uint8Array(10);
|
||||||
|
Uint8Array.fromBase64Into(throwyToString, target, touchyOptions);
|
||||||
|
});
|
||||||
|
assert.sameValue(toStringCalls, 0);
|
||||||
|
assert.sameValue(optionAccesses, 0);
|
17
test/built-ins/Uint8Array/fromBase64Into/subarray.js
Normal file
17
test/built-ins/Uint8Array/fromBase64Into/subarray.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64into
|
||||||
|
description: Uint8Array.fromBase64Into takes into account the offset of the target Uint8Array
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var base = new Uint8Array([255, 255, 255, 255, 255, 255, 255]);
|
||||||
|
var subarray = base.subarray(2, 5);
|
||||||
|
|
||||||
|
var result = Uint8Array.fromBase64Into('Zm9vYmFy', subarray);
|
||||||
|
assert.sameValue(result.read, 4);
|
||||||
|
assert.sameValue(result.written, 3);
|
||||||
|
assert.compareArray(subarray, [102, 111, 111]);
|
||||||
|
assert.compareArray(base, [255, 255, 102, 111, 111, 255, 255]);
|
64
test/built-ins/Uint8Array/fromBase64Into/target-size.js
Normal file
64
test/built-ins/Uint8Array/fromBase64Into/target-size.js
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64
|
||||||
|
description: Uint8Array.fromBase64Into behavior when target buffer is small
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// buffer too small
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('Zm9vYmFy', target);
|
||||||
|
assert.sameValue(result.read, 4);
|
||||||
|
assert.sameValue(result.written, 3);
|
||||||
|
assert.compareArray(target, [102, 111, 111, 255, 255]);
|
||||||
|
|
||||||
|
// buffer too small, padded
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('Zm9vYmE=', target);
|
||||||
|
assert.sameValue(result.read, 4);
|
||||||
|
assert.sameValue(result.written, 3);
|
||||||
|
assert.compareArray(target, [102, 111, 111, 255]);
|
||||||
|
|
||||||
|
// buffer exact
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('Zm9vYmFy', target);
|
||||||
|
assert.sameValue(result.read, 8);
|
||||||
|
assert.sameValue(result.written, 6);
|
||||||
|
assert.compareArray(target, [102, 111, 111, 98, 97, 114]);
|
||||||
|
|
||||||
|
// buffer exact, padded
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('Zm9vYmE=', target);
|
||||||
|
assert.sameValue(result.read, 8);
|
||||||
|
assert.sameValue(result.written, 5);
|
||||||
|
assert.compareArray(target, [102, 111, 111, 98, 97]);
|
||||||
|
|
||||||
|
// buffer exact, not padded
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('Zm9vYmE', target);
|
||||||
|
assert.sameValue(result.read, 7);
|
||||||
|
assert.sameValue(result.written, 5);
|
||||||
|
assert.compareArray(target, [102, 111, 111, 98, 97]);
|
||||||
|
|
||||||
|
// buffer exact, padded, stop-before-partial
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('Zm9vYmE=', target, { lastChunkHandling: 'stop-before-partial' });
|
||||||
|
assert.sameValue(result.read, 8);
|
||||||
|
assert.sameValue(result.written, 5);
|
||||||
|
assert.compareArray(target, [102, 111, 111, 98, 97]);
|
||||||
|
|
||||||
|
// buffer exact, not padded, stop-before-partial
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('Zm9vYmE', target, { lastChunkHandling: 'stop-before-partial' });
|
||||||
|
assert.sameValue(result.read, 4);
|
||||||
|
assert.sameValue(result.written, 3);
|
||||||
|
assert.compareArray(target, [102, 111, 111, 255, 255]);
|
||||||
|
|
||||||
|
// buffer too large
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into('Zm9vYmFy', target);
|
||||||
|
assert.sameValue(result.read, 8);
|
||||||
|
assert.sameValue(result.written, 6);
|
||||||
|
assert.compareArray(target, [102, 111, 111, 98, 97, 114, 255]);
|
23
test/built-ins/Uint8Array/fromBase64Into/whitespace.js
Normal file
23
test/built-ins/Uint8Array/fromBase64Into/whitespace.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.frombase64into
|
||||||
|
description: Uint8Array.fromBase64Into ignores ASCII whitespace in the input
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var whitespaceKinds = [
|
||||||
|
["Z g==", "space"],
|
||||||
|
["Z\tg==", "tab"],
|
||||||
|
["Z\x0Ag==", "LF"],
|
||||||
|
["Z\x0Cg==", "FF"],
|
||||||
|
["Z\x0Dg==", "CR"],
|
||||||
|
];
|
||||||
|
whitespaceKinds.forEach(function(pair) {
|
||||||
|
var target = new Uint8Array([255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromBase64Into(pair[0], target);
|
||||||
|
assert.sameValue(result.read, 5);
|
||||||
|
assert.sameValue(result.written, 1);
|
||||||
|
assert.compareArray(target, [102, 255, 255], "ascii whitespace: " + pair[1]);
|
||||||
|
});
|
15
test/built-ins/Uint8Array/fromHex/descriptor.js
Normal file
15
test/built-ins/Uint8Array/fromHex/descriptor.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhex
|
||||||
|
description: >
|
||||||
|
Uint8Array.fromHex has default data property attributes.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array, 'fromHex', {
|
||||||
|
enumerable: false,
|
||||||
|
writable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
19
test/built-ins/Uint8Array/fromHex/ignores-receiver.js
Normal file
19
test/built-ins/Uint8Array/fromHex/ignores-receiver.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhex
|
||||||
|
description: Uint8Array.fromHex ignores its receiver
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var fromHex = Uint8Array.fromHex;
|
||||||
|
var noReceiver = fromHex("aa");
|
||||||
|
assert.sameValue(Object.getPrototypeOf(noReceiver), Uint8Array.prototype);
|
||||||
|
|
||||||
|
class Subclass extends Uint8Array {
|
||||||
|
constructor() {
|
||||||
|
throw new Test262Error("subclass constructor called");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var fromSubclass = Subclass.fromHex("aa");
|
||||||
|
assert.sameValue(Object.getPrototypeOf(fromSubclass), Uint8Array.prototype);
|
25
test/built-ins/Uint8Array/fromHex/illegal-characters.js
Normal file
25
test/built-ins/Uint8Array/fromHex/illegal-characters.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhex
|
||||||
|
description: Uint8Array.fromHex throws a SyntaxError when input has non-hex characters
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var illegal = [
|
||||||
|
'a.a',
|
||||||
|
'aa^',
|
||||||
|
'a a',
|
||||||
|
'a\ta',
|
||||||
|
'a\x0Aa',
|
||||||
|
'a\x0Ca',
|
||||||
|
'a\x0Da',
|
||||||
|
'a\u00A0a', // nbsp
|
||||||
|
'a\u2009a', // thin space
|
||||||
|
'a\u2028a', // line separator
|
||||||
|
];
|
||||||
|
illegal.forEach(function(value) {
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
Uint8Array.fromHex(value)
|
||||||
|
});
|
||||||
|
});
|
16
test/built-ins/Uint8Array/fromHex/length.js
Normal file
16
test/built-ins/Uint8Array/fromHex/length.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhex
|
||||||
|
description: >
|
||||||
|
Uint8Array.fromHex.length is 1.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array.fromHex, 'length', {
|
||||||
|
value: 1,
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
16
test/built-ins/Uint8Array/fromHex/name.js
Normal file
16
test/built-ins/Uint8Array/fromHex/name.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhex
|
||||||
|
description: >
|
||||||
|
Uint8Array.fromHex.name is "fromHex".
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array.fromHex, 'name', {
|
||||||
|
value: 'fromHex',
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
15
test/built-ins/Uint8Array/fromHex/nonconstructor.js
Normal file
15
test/built-ins/Uint8Array/fromHex/nonconstructor.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhex
|
||||||
|
description: >
|
||||||
|
Uint8Array.fromHex is not a constructor function.
|
||||||
|
includes: [isConstructor.js]
|
||||||
|
features: [uint8array-base64, Reflect.construct]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert(!isConstructor(Uint8Array.fromHex), "Uint8Array.fromHex is not a constructor");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
new Uint8Array.fromHex('');
|
||||||
|
});
|
11
test/built-ins/Uint8Array/fromHex/odd-length-input.js
Normal file
11
test/built-ins/Uint8Array/fromHex/odd-length-input.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhex
|
||||||
|
description: Uint8Array.fromHex throws if given an odd number of input hex characters
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
Uint8Array.fromHex('a');
|
||||||
|
});
|
26
test/built-ins/Uint8Array/fromHex/results.js
Normal file
26
test/built-ins/Uint8Array/fromHex/results.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhex
|
||||||
|
description: Conversion of hex strings to Uint8Arrays
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var cases = [
|
||||||
|
["", []],
|
||||||
|
["66", [102]],
|
||||||
|
["666f", [102, 111]],
|
||||||
|
["666F", [102, 111]],
|
||||||
|
["666f6f", [102, 111, 111]],
|
||||||
|
["666F6f", [102, 111, 111]],
|
||||||
|
["666f6f62", [102, 111, 111, 98]],
|
||||||
|
["666f6f6261", [102, 111, 111, 98, 97]],
|
||||||
|
["666f6f626172", [102, 111, 111, 98, 97, 114]],
|
||||||
|
];
|
||||||
|
|
||||||
|
cases.forEach(function (pair) {
|
||||||
|
var arr = Uint8Array.fromHex(pair[0]);
|
||||||
|
assert.sameValue(Object.getPrototypeOf(arr), Uint8Array.prototype, "decoding " + pair[0]);
|
||||||
|
assert.compareArray(arr, pair[1], "decoding " + pair[0]);
|
||||||
|
});
|
20
test/built-ins/Uint8Array/fromHex/string-coercion.js
Normal file
20
test/built-ins/Uint8Array/fromHex/string-coercion.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhex
|
||||||
|
description: Uint8Array.fromHex throws if its argument is not a string
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var toStringCalls = 0;
|
||||||
|
var throwyToString = {
|
||||||
|
toString: function() {
|
||||||
|
toStringCalls += 1;
|
||||||
|
throw new Test262Error("toString called");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Uint8Array.fromHex(throwyToString);
|
||||||
|
});
|
||||||
|
assert.sameValue(toStringCalls, 0);
|
15
test/built-ins/Uint8Array/fromHexInto/descriptor.js
Normal file
15
test/built-ins/Uint8Array/fromHexInto/descriptor.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhexinto
|
||||||
|
description: >
|
||||||
|
Uint8Array.fromHexInto has default data property attributes.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array, 'fromHexInto', {
|
||||||
|
enumerable: false,
|
||||||
|
writable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
14
test/built-ins/Uint8Array/fromHexInto/detached-buffer.js
Normal file
14
test/built-ins/Uint8Array/fromHexInto/detached-buffer.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhexinto
|
||||||
|
description: Uint8Array.fromHexInto does not write to or error on detatched buffers
|
||||||
|
includes: [detachArrayBuffer.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var target = new Uint8Array([255, 255, 255]);
|
||||||
|
$DETACHBUFFER(target.buffer);
|
||||||
|
var result = Uint8Array.fromHexInto('aa', target);
|
||||||
|
assert.sameValue(result.read, 0);
|
||||||
|
assert.sameValue(result.written, 0);
|
16
test/built-ins/Uint8Array/fromHexInto/ignores-receiver.js
Normal file
16
test/built-ins/Uint8Array/fromHexInto/ignores-receiver.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhexinto
|
||||||
|
description: Uint8Array.fromHexInto ignores its receiver
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var fromHexInto = Uint8Array.fromHexInto;
|
||||||
|
var target = new Uint8Array([255, 255, 255]);
|
||||||
|
|
||||||
|
var result = fromHexInto("aa", target);
|
||||||
|
assert.sameValue(result.read, 2);
|
||||||
|
assert.sameValue(result.written, 1);
|
||||||
|
assert.compareArray(target, [170, 255, 255]);
|
26
test/built-ins/Uint8Array/fromHexInto/illegal-characters.js
Normal file
26
test/built-ins/Uint8Array/fromHexInto/illegal-characters.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhexinto
|
||||||
|
description: Uint8Array.fromHexInto throws a SyntaxError when input has non-hex characters
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var illegal = [
|
||||||
|
'a.a',
|
||||||
|
'aa^',
|
||||||
|
'a a',
|
||||||
|
'a\ta',
|
||||||
|
'a\x0Aa',
|
||||||
|
'a\x0Ca',
|
||||||
|
'a\x0Da',
|
||||||
|
'a\u00A0a', // nbsp
|
||||||
|
'a\u2009a', // thin space
|
||||||
|
'a\u2028a', // line separator
|
||||||
|
];
|
||||||
|
illegal.forEach(function(value) {
|
||||||
|
assert.throws(SyntaxError, function() {
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255, 255]);
|
||||||
|
Uint8Array.fromHexInto(value, target);
|
||||||
|
});
|
||||||
|
});
|
16
test/built-ins/Uint8Array/fromHexInto/length.js
Normal file
16
test/built-ins/Uint8Array/fromHexInto/length.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhexinto
|
||||||
|
description: >
|
||||||
|
Uint8Array.fromHexInto.length is 2.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array.fromHexInto, 'length', {
|
||||||
|
value: 2,
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
16
test/built-ins/Uint8Array/fromHexInto/name.js
Normal file
16
test/built-ins/Uint8Array/fromHexInto/name.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhexinto
|
||||||
|
description: >
|
||||||
|
Uint8Array.fromHexInto.name is "fromHexInto".
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array.fromHexInto, 'name', {
|
||||||
|
value: 'fromHexInto',
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
16
test/built-ins/Uint8Array/fromHexInto/nonconstructor.js
Normal file
16
test/built-ins/Uint8Array/fromHexInto/nonconstructor.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhexinto
|
||||||
|
description: >
|
||||||
|
Uint8Array.fromHexInto is not a constructor function.
|
||||||
|
includes: [isConstructor.js]
|
||||||
|
features: [uint8array-base64, Reflect.construct]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert(!isConstructor(Uint8Array.fromHexInto), "Uint8Array.fromHexInto is not a constructor");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
var target = new Uint8Array(10);
|
||||||
|
new Uint8Array.fromHexInto('', target);
|
||||||
|
});
|
31
test/built-ins/Uint8Array/fromHexInto/results.js
Normal file
31
test/built-ins/Uint8Array/fromHexInto/results.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhexinto
|
||||||
|
description: Conversion of hex strings to Uint8Arrays
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var cases = [
|
||||||
|
["", []],
|
||||||
|
["66", [102]],
|
||||||
|
["666f", [102, 111]],
|
||||||
|
["666F", [102, 111]],
|
||||||
|
["666f6f", [102, 111, 111]],
|
||||||
|
["666F6f", [102, 111, 111]],
|
||||||
|
["666f6f62", [102, 111, 111, 98]],
|
||||||
|
["666f6f6261", [102, 111, 111, 98, 97]],
|
||||||
|
["666f6f626172", [102, 111, 111, 98, 97, 114]],
|
||||||
|
];
|
||||||
|
|
||||||
|
cases.forEach(function (pair) {
|
||||||
|
var allFF = [255, 255, 255, 255, 255, 255, 255, 255];
|
||||||
|
var target = new Uint8Array(allFF);
|
||||||
|
var result = Uint8Array.fromHexInto(pair[0], target);
|
||||||
|
assert.sameValue(result.read, pair[0].length);
|
||||||
|
assert.sameValue(result.written, pair[1].length);
|
||||||
|
|
||||||
|
var expected = pair[1].concat(allFF.slice(pair[1].length))
|
||||||
|
assert.compareArray(target, expected, "decoding " + pair[0]);
|
||||||
|
});
|
21
test/built-ins/Uint8Array/fromHexInto/string-coercion.js
Normal file
21
test/built-ins/Uint8Array/fromHexInto/string-coercion.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhexinto
|
||||||
|
description: Uint8Array.fromHexInto throws if its first argument is not a string
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var toStringCalls = 0;
|
||||||
|
var throwyToString = {
|
||||||
|
toString: function() {
|
||||||
|
toStringCalls += 1;
|
||||||
|
throw new Test262Error("toString called");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
var target = new Uint8Array(10);
|
||||||
|
Uint8Array.fromHexInto(throwyToString, target);
|
||||||
|
});
|
||||||
|
assert.sameValue(toStringCalls, 0);
|
17
test/built-ins/Uint8Array/fromHexInto/subarray.js
Normal file
17
test/built-ins/Uint8Array/fromHexInto/subarray.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhexinto
|
||||||
|
description: Uint8Array.fromHexInto takes into account the offset of the target Uint8Array
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var base = new Uint8Array([255, 255, 255, 255, 255, 255, 255]);
|
||||||
|
var subarray = base.subarray(2, 5);
|
||||||
|
|
||||||
|
var result = Uint8Array.fromHexInto('aabbcc', subarray);
|
||||||
|
assert.sameValue(result.read, 6);
|
||||||
|
assert.sameValue(result.written, 3);
|
||||||
|
assert.compareArray(subarray, [170, 187, 204]);
|
||||||
|
assert.compareArray(base, [255, 255, 170, 187, 204, 255, 255]);
|
29
test/built-ins/Uint8Array/fromHexInto/target-size.js
Normal file
29
test/built-ins/Uint8Array/fromHexInto/target-size.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-uint8array.fromhexinto
|
||||||
|
description: Uint8Array.fromHexInto behavior when target buffer is small
|
||||||
|
includes: [compareArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// buffer too small
|
||||||
|
var target = new Uint8Array([255, 255]);
|
||||||
|
var result = Uint8Array.fromHexInto('aabbcc', target);
|
||||||
|
assert.sameValue(result.read, 4);
|
||||||
|
assert.sameValue(result.written, 2);
|
||||||
|
assert.compareArray(target, [170, 187]);
|
||||||
|
|
||||||
|
// buffer exact
|
||||||
|
var target = new Uint8Array([255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromHexInto('aabbcc', target);
|
||||||
|
assert.sameValue(result.read, 6);
|
||||||
|
assert.sameValue(result.written, 3);
|
||||||
|
assert.compareArray(target, [170, 187, 204]);
|
||||||
|
|
||||||
|
// buffer too large
|
||||||
|
var target = new Uint8Array([255, 255, 255, 255]);
|
||||||
|
var result = Uint8Array.fromHexInto('aabbcc', target);
|
||||||
|
assert.sameValue(result.read, 6);
|
||||||
|
assert.sameValue(result.written, 3);
|
||||||
|
assert.compareArray(target, [170, 187, 204, 255]);
|
17
test/built-ins/Uint8Array/prototype/toBase64/alphabet.js
vendored
Normal file
17
test/built-ins/Uint8Array/prototype/toBase64/alphabet.js
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// 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.tobase64
|
||||||
|
description: Conversion of Uint8Arrays to base64 strings exercising the alphabet option
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue((new Uint8Array([199, 239, 242])).toBase64(), "x+/y");
|
||||||
|
|
||||||
|
assert.sameValue((new Uint8Array([199, 239, 242])).toBase64({ alphabet: 'base64' }), "x+/y");
|
||||||
|
|
||||||
|
assert.sameValue((new Uint8Array([199, 239, 242])).toBase64({ alphabet: 'base64url' }), "x-_y");
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
(new Uint8Array([199, 239, 242])).toBase64({ alphabet: 'other' });
|
||||||
|
});
|
15
test/built-ins/Uint8Array/prototype/toBase64/descriptor.js
vendored
Normal file
15
test/built-ins/Uint8Array/prototype/toBase64/descriptor.js
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// 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.tobase64
|
||||||
|
description: >
|
||||||
|
Uint8Array.prototype.toBase64 has default data property attributes.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array.prototype, 'toBase64', {
|
||||||
|
enumerable: false,
|
||||||
|
writable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
39
test/built-ins/Uint8Array/prototype/toBase64/detached-buffer.js
vendored
Normal file
39
test/built-ins/Uint8Array/prototype/toBase64/detached-buffer.js
vendored
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// 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.tobase64
|
||||||
|
description: Uint8Array.prototype.toBase64 checks for detachedness after side-effects are finished
|
||||||
|
includes: [detachArrayBuffer.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var array = new Uint8Array(2);
|
||||||
|
var getterCalls = 0;
|
||||||
|
var recevierDetachingOptions = {};
|
||||||
|
Object.defineProperty(recevierDetachingOptions, "alphabet", {
|
||||||
|
get: function() {
|
||||||
|
getterCalls += 1;
|
||||||
|
$DETACHBUFFER(array.buffer);
|
||||||
|
return "base64";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
array.toBase64(recevierDetachingOptions);
|
||||||
|
});
|
||||||
|
assert.sameValue(getterCalls, 1);
|
||||||
|
|
||||||
|
|
||||||
|
var detached = new Uint8Array(2);
|
||||||
|
$DETACHBUFFER(detached.buffer);
|
||||||
|
var getterCalls = 0;
|
||||||
|
var sideEffectingOptions = {};
|
||||||
|
Object.defineProperty(sideEffectingOptions, "alphabet", {
|
||||||
|
get: function() {
|
||||||
|
getterCalls += 1;
|
||||||
|
return "base64";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
detached.toBase64(sideEffectingOptions);
|
||||||
|
});
|
||||||
|
assert.sameValue(getterCalls, 1);
|
16
test/built-ins/Uint8Array/prototype/toBase64/length.js
vendored
Normal file
16
test/built-ins/Uint8Array/prototype/toBase64/length.js
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// 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.tobase64
|
||||||
|
description: >
|
||||||
|
Uint8Array.prototype.toBase64.length is 0.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array.prototype.toBase64, 'length', {
|
||||||
|
value: 0,
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
16
test/built-ins/Uint8Array/prototype/toBase64/name.js
vendored
Normal file
16
test/built-ins/Uint8Array/prototype/toBase64/name.js
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// 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.tobase64
|
||||||
|
description: >
|
||||||
|
Uint8Array.prototype.toBase64.name is "toBase64".
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array.prototype.toBase64, 'name', {
|
||||||
|
value: 'toBase64',
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
16
test/built-ins/Uint8Array/prototype/toBase64/nonconstructor.js
vendored
Normal file
16
test/built-ins/Uint8Array/prototype/toBase64/nonconstructor.js
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// 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.tobase64
|
||||||
|
description: >
|
||||||
|
Uint8Array.prototype.toBase64 is not a constructor function.
|
||||||
|
includes: [isConstructor.js]
|
||||||
|
features: [uint8array-base64, Reflect.construct]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert(!isConstructor(Uint8Array.prototype.toBase64), "Uint8Array.prototype.toBase64 is not a constructor");
|
||||||
|
|
||||||
|
var uint8Array = new Uint8Array(8);
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
new uint8Array.toBase64();
|
||||||
|
});
|
43
test/built-ins/Uint8Array/prototype/toBase64/option-coercion.js
vendored
Normal file
43
test/built-ins/Uint8Array/prototype/toBase64/option-coercion.js
vendored
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
// 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.tobase64
|
||||||
|
description: Uint8Array.prototype.toBase64 triggers effects of the "alphabet" getter, but does not perform toString on the result
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var toStringCalls = 0;
|
||||||
|
var throwyToString = {
|
||||||
|
toString: function() {
|
||||||
|
toStringCalls += 1;
|
||||||
|
throw new Test262Error("toString called on alphabet value");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
(new Uint8Array(2)).toBase64({ alphabet: throwyToString });
|
||||||
|
});
|
||||||
|
assert.sameValue(toStringCalls, 0);
|
||||||
|
|
||||||
|
var alphabetAccesses = 0;
|
||||||
|
var base64UrlOptions = {};
|
||||||
|
Object.defineProperty(base64UrlOptions, "alphabet", {
|
||||||
|
get: function() {
|
||||||
|
alphabetAccesses += 1;
|
||||||
|
return "base64url";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert.sameValue((new Uint8Array([199, 239, 242])).toBase64(base64UrlOptions), "x-_y");
|
||||||
|
assert.sameValue(alphabetAccesses, 1);
|
||||||
|
|
||||||
|
// side-effects from the getter on the receiver are reflected in the result
|
||||||
|
var array = new Uint8Array([0]);
|
||||||
|
var recevierMutatingOptions = {};
|
||||||
|
Object.defineProperty(recevierMutatingOptions, "alphabet", {
|
||||||
|
get: function() {
|
||||||
|
array[0] = 255;
|
||||||
|
return "base64";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var result = array.toBase64(recevierMutatingOptions);
|
||||||
|
assert.sameValue(result, "/w==");
|
||||||
|
assert.sameValue(array[0], 255);
|
33
test/built-ins/Uint8Array/prototype/toBase64/receiver-not-uint8array.js
vendored
Normal file
33
test/built-ins/Uint8Array/prototype/toBase64/receiver-not-uint8array.js
vendored
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// 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.tobase64
|
||||||
|
description: Uint8Array.prototype.toBase64 throws if the receiver is not a Uint8Array
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var toBase64 = Uint8Array.prototype.toBase64;
|
||||||
|
|
||||||
|
var options = {};
|
||||||
|
Object.defineProperty(options, "alphabet", {
|
||||||
|
get: function() {
|
||||||
|
throw new Test262Error("options.alphabet accessed despite incompatible receiver");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
if (TA === Uint8Array) return;
|
||||||
|
var sample = new TA(2);
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Uint8Array.prototype.toBase64.call(sample, options);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Uint8Array.prototype.toBase64.call([], options);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
toBase64(options);
|
||||||
|
});
|
16
test/built-ins/Uint8Array/prototype/toBase64/results.js
vendored
Normal file
16
test/built-ins/Uint8Array/prototype/toBase64/results.js
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// 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.tobase64
|
||||||
|
description: Conversion of Uint8Arrays to base64 strings
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// standard test vectors from https://datatracker.ietf.org/doc/html/rfc4648#section-10
|
||||||
|
assert.sameValue((new Uint8Array([])).toBase64(), "");
|
||||||
|
assert.sameValue((new Uint8Array([102])).toBase64(), "Zg==");
|
||||||
|
assert.sameValue((new Uint8Array([102, 111])).toBase64(), "Zm8=");
|
||||||
|
assert.sameValue((new Uint8Array([102, 111, 111])).toBase64(), "Zm9v");
|
||||||
|
assert.sameValue((new Uint8Array([102, 111, 111, 98])).toBase64(), "Zm9vYg==");
|
||||||
|
assert.sameValue((new Uint8Array([102, 111, 111, 98, 97])).toBase64(), "Zm9vYmE=");
|
||||||
|
assert.sameValue((new Uint8Array([102, 111, 111, 98, 97, 114])).toBase64(), "Zm9vYmFy");
|
15
test/built-ins/Uint8Array/prototype/toHex/descriptor.js
vendored
Normal file
15
test/built-ins/Uint8Array/prototype/toHex/descriptor.js
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// 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.tohex
|
||||||
|
description: >
|
||||||
|
Uint8Array.prototype.toHex has default data property attributes.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array.prototype, 'toHex', {
|
||||||
|
enumerable: false,
|
||||||
|
writable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
15
test/built-ins/Uint8Array/prototype/toHex/detached-buffer.js
vendored
Normal file
15
test/built-ins/Uint8Array/prototype/toHex/detached-buffer.js
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// 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.tohex
|
||||||
|
description: Uint8Array.prototype.toHex throws if called on a detached buffer
|
||||||
|
includes: [detachArrayBuffer.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var array = new Uint8Array(2);
|
||||||
|
$DETACHBUFFER(array.buffer);
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
array.toHex();
|
||||||
|
});
|
||||||
|
|
16
test/built-ins/Uint8Array/prototype/toHex/length.js
vendored
Normal file
16
test/built-ins/Uint8Array/prototype/toHex/length.js
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// 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.tohex
|
||||||
|
description: >
|
||||||
|
Uint8Array.prototype.toHex.length is 0.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array.prototype.toHex, 'length', {
|
||||||
|
value: 0,
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
16
test/built-ins/Uint8Array/prototype/toHex/name.js
vendored
Normal file
16
test/built-ins/Uint8Array/prototype/toHex/name.js
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// 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.tohex
|
||||||
|
description: >
|
||||||
|
Uint8Array.prototype.toHex.name is "toHex".
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyProperty(Uint8Array.prototype.toHex, 'name', {
|
||||||
|
value: 'toHex',
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
configurable: true
|
||||||
|
});
|
16
test/built-ins/Uint8Array/prototype/toHex/nonconstructor.js
vendored
Normal file
16
test/built-ins/Uint8Array/prototype/toHex/nonconstructor.js
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// 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.tohex
|
||||||
|
description: >
|
||||||
|
Uint8Array.prototype.toHex is not a constructor function.
|
||||||
|
includes: [isConstructor.js]
|
||||||
|
features: [uint8array-base64, Reflect.construct]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert(!isConstructor(Uint8Array.prototype.toHex), "Uint8Array.prototype.toHex is not a constructor");
|
||||||
|
|
||||||
|
var uint8Array = new Uint8Array(8);
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
new uint8Array.toHex();
|
||||||
|
});
|
26
test/built-ins/Uint8Array/prototype/toHex/receiver-not-uint8array.js
vendored
Normal file
26
test/built-ins/Uint8Array/prototype/toHex/receiver-not-uint8array.js
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// 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.tohex
|
||||||
|
description: Uint8Array.prototype.toHex throws if the receiver is not a Uint8Array
|
||||||
|
includes: [testTypedArray.js]
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var toHex = Uint8Array.prototype.toHex;
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
if (TA === Uint8Array) return;
|
||||||
|
var sample = new TA(2);
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Uint8Array.prototype.toHex.call(sample);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Uint8Array.prototype.toHex.call([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
toHex();
|
||||||
|
});
|
15
test/built-ins/Uint8Array/prototype/toHex/results.js
vendored
Normal file
15
test/built-ins/Uint8Array/prototype/toHex/results.js
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// 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.tohex
|
||||||
|
description: Conversion of Uint8Arrays to hex strings
|
||||||
|
features: [uint8array-base64]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue((new Uint8Array([])).toHex(), "");
|
||||||
|
assert.sameValue((new Uint8Array([102])).toHex(), "66");
|
||||||
|
assert.sameValue((new Uint8Array([102, 111])).toHex(), "666f");
|
||||||
|
assert.sameValue((new Uint8Array([102, 111, 111])).toHex(), "666f6f");
|
||||||
|
assert.sameValue((new Uint8Array([102, 111, 111, 98])).toHex(), "666f6f62");
|
||||||
|
assert.sameValue((new Uint8Array([102, 111, 111, 98, 97])).toHex(), "666f6f6261");
|
||||||
|
assert.sameValue((new Uint8Array([102, 111, 111, 98, 97, 114])).toHex(), "666f6f626172");
|
Loading…
x
Reference in New Issue
Block a user