From fc22df955222b5afee10ab5255a0fed6c14a4110 Mon Sep 17 00:00:00 2001 From: ZYSzys <17367077526@163.com> Date: Wed, 26 Dec 2018 17:30:26 +0800 Subject: [PATCH] test: more tests for internal/util/types PR-URL: https://github.com/nodejs/node/pull/25225 Reviewed-By: James M Snell Reviewed-By: Michael Dawson --- test/parallel/test-util-types.js | 138 +++++++++++++++++++++++++++---- 1 file changed, 123 insertions(+), 15 deletions(-) diff --git a/test/parallel/test-util-types.js b/test/parallel/test-util-types.js index 19b265ca2a7c96..69ebaaba12b00f 100644 --- a/test/parallel/test-util-types.js +++ b/test/parallel/test-util-types.js @@ -121,39 +121,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 ] };