Skip to content

Commit

Permalink
test: more tests for internal/util/types
Browse files Browse the repository at this point in the history
PR-URL: #25225
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
  • Loading branch information
ZYSzys authored and MylesBorins committed May 16, 2019
1 parent 252a696 commit c103e98
Showing 1 changed file with 123 additions and 15 deletions.
138 changes: 123 additions & 15 deletions test/parallel/test-util-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,39 +120,147 @@ for (const [ value, _method ] of [
{
const primitive = true;
const arrayBuffer = new ArrayBuffer();
const buffer = Buffer.from(arrayBuffer);
const dataView = new DataView(arrayBuffer);
const int32Array = new Int32Array(arrayBuffer);
const uint8Array = new Uint8Array(arrayBuffer);
const buffer = Buffer.from(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 fakeBuffer = Object.create(Buffer.prototype);
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 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 =
Object.setPrototypeOf(new DataView(arrayBuffer), Uint8Array.prototype);
const stealthyInt32Array =
Object.setPrototypeOf(new Int32Array(arrayBuffer), uint8Array);
Object.setPrototypeOf(new DataView(arrayBuffer), Uint8Array.prototype);
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 = [
primitive, arrayBuffer, dataView, int32Array, uint8Array, buffer,
fakeDataView, fakeInt32Array, fakeUint8Array, fakeBuffer,
stealthyDataView, stealthyInt32Array, stealthyUint8Array
primitive, arrayBuffer, buffer, fakeBuffer,
dataView, fakeDataView, stealthyDataView,
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 = {
isArrayBufferView: [
dataView, int32Array, uint8Array, buffer,
stealthyDataView, stealthyInt32Array, stealthyUint8Array
buffer,
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: [
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: [
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
]
};

Expand Down

0 comments on commit c103e98

Please sign in to comment.