test: more tests for internal/util/types
PR-URL: https://github.com/nodejs/node/pull/25225 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
This commit is contained in:
parent
aa07dd6248
commit
519a11b24f
@ -121,39 +121,147 @@ for (const [ value, _method ] of [
|
|||||||
{
|
{
|
||||||
const primitive = true;
|
const primitive = true;
|
||||||
const arrayBuffer = new ArrayBuffer();
|
const arrayBuffer = new ArrayBuffer();
|
||||||
const dataView = new DataView(arrayBuffer);
|
|
||||||
const int32Array = new Int32Array(arrayBuffer);
|
|
||||||
const uint8Array = new Uint8Array(arrayBuffer);
|
|
||||||
const buffer = Buffer.from(arrayBuffer);
|
const buffer = Buffer.from(arrayBuffer);
|
||||||
|
const dataView = new DataView(arrayBuffer);
|
||||||
|
const uint8Array = new Uint8Array(arrayBuffer);
|
||||||
|
const uint8ClampedArray = new Uint8ClampedArray(arrayBuffer);
|
||||||
|
const uint16Array = new Uint16Array(arrayBuffer);
|
||||||
|
const uint32Array = new Uint32Array(arrayBuffer);
|
||||||
|
const int8Array = new Int8Array(arrayBuffer);
|
||||||
|
const int16Array = new Int16Array(arrayBuffer);
|
||||||
|
const int32Array = new Int32Array(arrayBuffer);
|
||||||
|
const float32Array = new Float32Array(arrayBuffer);
|
||||||
|
const float64Array = new Float64Array(arrayBuffer);
|
||||||
|
const bigInt64Array = new BigInt64Array(arrayBuffer);
|
||||||
|
const bigUint64Array = new BigUint64Array(arrayBuffer);
|
||||||
|
|
||||||
const fakeDataView = Object.create(DataView.prototype);
|
|
||||||
const fakeInt32Array = Object.create(Int32Array.prototype);
|
|
||||||
const fakeUint8Array = Object.create(Uint8Array.prototype);
|
|
||||||
const fakeBuffer = Object.create(Buffer.prototype);
|
const fakeBuffer = Object.create(Buffer.prototype);
|
||||||
|
const fakeDataView = Object.create(DataView.prototype);
|
||||||
|
const fakeUint8Array = Object.create(Uint8Array.prototype);
|
||||||
|
const fakeUint8ClampedArray = Object.create(Uint8ClampedArray.prototype);
|
||||||
|
const fakeUint16Array = Object.create(Uint16Array.prototype);
|
||||||
|
const fakeUint32Array = Object.create(Uint32Array.prototype);
|
||||||
|
const fakeInt8Array = Object.create(Int8Array.prototype);
|
||||||
|
const fakeInt16Array = Object.create(Int16Array.prototype);
|
||||||
|
const fakeInt32Array = Object.create(Int32Array.prototype);
|
||||||
|
const fakeFloat32Array = Object.create(Float32Array.prototype);
|
||||||
|
const fakeFloat64Array = Object.create(Float64Array.prototype);
|
||||||
|
const fakeBigInt64Array = Object.create(BigInt64Array.prototype);
|
||||||
|
const fakeBigUint64Array = Object.create(BigUint64Array.prototype);
|
||||||
|
|
||||||
const stealthyDataView =
|
const stealthyDataView =
|
||||||
Object.setPrototypeOf(new DataView(arrayBuffer), Uint8Array.prototype);
|
Object.setPrototypeOf(new DataView(arrayBuffer), Uint8Array.prototype);
|
||||||
const stealthyInt32Array =
|
|
||||||
Object.setPrototypeOf(new Int32Array(arrayBuffer), uint8Array);
|
|
||||||
const stealthyUint8Array =
|
const stealthyUint8Array =
|
||||||
Object.setPrototypeOf(new Uint8Array(arrayBuffer), ArrayBuffer.prototype);
|
Object.setPrototypeOf(new Uint8Array(arrayBuffer), ArrayBuffer.prototype);
|
||||||
|
const stealthyUint8ClampedArray =
|
||||||
|
Object.setPrototypeOf(
|
||||||
|
new Uint8ClampedArray(arrayBuffer), ArrayBuffer.prototype
|
||||||
|
);
|
||||||
|
const stealthyUint16Array =
|
||||||
|
Object.setPrototypeOf(new Uint16Array(arrayBuffer), Uint16Array.prototype);
|
||||||
|
const stealthyUint32Array =
|
||||||
|
Object.setPrototypeOf(new Uint32Array(arrayBuffer), Uint32Array.prototype);
|
||||||
|
const stealthyInt8Array =
|
||||||
|
Object.setPrototypeOf(new Int8Array(arrayBuffer), Int8Array.prototype);
|
||||||
|
const stealthyInt16Array =
|
||||||
|
Object.setPrototypeOf(new Int16Array(arrayBuffer), Int16Array.prototype);
|
||||||
|
const stealthyInt32Array =
|
||||||
|
Object.setPrototypeOf(new Int32Array(arrayBuffer), Int32Array.prototype);
|
||||||
|
const stealthyFloat32Array =
|
||||||
|
Object.setPrototypeOf(
|
||||||
|
new Float32Array(arrayBuffer), Float32Array.prototype
|
||||||
|
);
|
||||||
|
const stealthyFloat64Array =
|
||||||
|
Object.setPrototypeOf(
|
||||||
|
new Float64Array(arrayBuffer), Float64Array.prototype
|
||||||
|
);
|
||||||
|
const stealthyBigInt64Array =
|
||||||
|
Object.setPrototypeOf(
|
||||||
|
new BigInt64Array(arrayBuffer), BigInt64Array.prototype
|
||||||
|
);
|
||||||
|
const stealthyBigUint64Array =
|
||||||
|
Object.setPrototypeOf(
|
||||||
|
new BigUint64Array(arrayBuffer), BigUint64Array.prototype
|
||||||
|
);
|
||||||
|
|
||||||
const all = [
|
const all = [
|
||||||
primitive, arrayBuffer, dataView, int32Array, uint8Array, buffer,
|
primitive, arrayBuffer, buffer, fakeBuffer,
|
||||||
fakeDataView, fakeInt32Array, fakeUint8Array, fakeBuffer,
|
dataView, fakeDataView, stealthyDataView,
|
||||||
stealthyDataView, stealthyInt32Array, stealthyUint8Array
|
uint8Array, fakeUint8Array, stealthyUint8Array,
|
||||||
|
uint8ClampedArray, fakeUint8ClampedArray, stealthyUint8ClampedArray,
|
||||||
|
uint16Array, fakeUint16Array, stealthyUint16Array,
|
||||||
|
uint32Array, fakeUint32Array, stealthyUint32Array,
|
||||||
|
int8Array, fakeInt8Array, stealthyInt8Array,
|
||||||
|
int16Array, fakeInt16Array, stealthyInt16Array,
|
||||||
|
int32Array, fakeInt32Array, stealthyInt32Array,
|
||||||
|
float32Array, fakeFloat32Array, stealthyFloat32Array,
|
||||||
|
float64Array, fakeFloat64Array, stealthyFloat64Array,
|
||||||
|
bigInt64Array, fakeBigInt64Array, stealthyBigInt64Array,
|
||||||
|
bigUint64Array, fakeBigUint64Array, stealthyBigUint64Array
|
||||||
];
|
];
|
||||||
|
|
||||||
const expected = {
|
const expected = {
|
||||||
isArrayBufferView: [
|
isArrayBufferView: [
|
||||||
dataView, int32Array, uint8Array, buffer,
|
buffer,
|
||||||
stealthyDataView, stealthyInt32Array, stealthyUint8Array
|
dataView, stealthyDataView,
|
||||||
|
uint8Array, stealthyUint8Array,
|
||||||
|
uint8ClampedArray, stealthyUint8ClampedArray,
|
||||||
|
uint16Array, stealthyUint16Array,
|
||||||
|
uint32Array, stealthyUint32Array,
|
||||||
|
int8Array, stealthyInt8Array,
|
||||||
|
int16Array, stealthyInt16Array,
|
||||||
|
int32Array, stealthyInt32Array,
|
||||||
|
float32Array, stealthyFloat32Array,
|
||||||
|
float64Array, stealthyFloat64Array,
|
||||||
|
bigInt64Array, stealthyBigInt64Array,
|
||||||
|
bigUint64Array, stealthyBigUint64Array
|
||||||
],
|
],
|
||||||
isTypedArray: [
|
isTypedArray: [
|
||||||
int32Array, uint8Array, buffer, stealthyInt32Array, stealthyUint8Array
|
buffer,
|
||||||
|
uint8Array, stealthyUint8Array,
|
||||||
|
uint8ClampedArray, stealthyUint8ClampedArray,
|
||||||
|
uint16Array, stealthyUint16Array,
|
||||||
|
uint32Array, stealthyUint32Array,
|
||||||
|
int8Array, stealthyInt8Array,
|
||||||
|
int16Array, stealthyInt16Array,
|
||||||
|
int32Array, stealthyInt32Array,
|
||||||
|
float32Array, stealthyFloat32Array,
|
||||||
|
float64Array, stealthyFloat64Array,
|
||||||
|
bigInt64Array, stealthyBigInt64Array,
|
||||||
|
bigUint64Array, stealthyBigUint64Array
|
||||||
],
|
],
|
||||||
isUint8Array: [
|
isUint8Array: [
|
||||||
uint8Array, buffer, stealthyUint8Array
|
buffer, uint8Array, stealthyUint8Array
|
||||||
|
],
|
||||||
|
isUint8ClampedArray: [
|
||||||
|
uint8ClampedArray, stealthyUint8ClampedArray
|
||||||
|
],
|
||||||
|
isUint16Array: [
|
||||||
|
uint16Array, stealthyUint16Array
|
||||||
|
],
|
||||||
|
isUint32Array: [
|
||||||
|
uint32Array, stealthyUint32Array
|
||||||
|
],
|
||||||
|
isInt8Array: [
|
||||||
|
int8Array, stealthyInt8Array
|
||||||
|
],
|
||||||
|
isInt16Array: [
|
||||||
|
int16Array, stealthyInt16Array
|
||||||
|
],
|
||||||
|
isInt32Array: [
|
||||||
|
int32Array, stealthyInt32Array
|
||||||
|
],
|
||||||
|
isFloat32Array: [
|
||||||
|
float32Array, stealthyFloat32Array
|
||||||
|
],
|
||||||
|
isFloat64Array: [
|
||||||
|
float64Array, stealthyFloat64Array
|
||||||
|
],
|
||||||
|
isBigInt64Array: [
|
||||||
|
bigInt64Array, stealthyBigInt64Array
|
||||||
|
],
|
||||||
|
isBigUint64Array: [
|
||||||
|
bigUint64Array, stealthyBigUint64Array
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user