From b2bc53bc44fcfaf09266ea5545509cbc1783731c Mon Sep 17 00:00:00 2001 From: Dante Calderon Date: Mon, 16 May 2022 21:01:28 -0500 Subject: [PATCH 1/3] Add tests for TypedArray#ElementSize --- test/typedarray.cc | 6 ++++++ test/typedarray.js | 20 +++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/test/typedarray.cc b/test/typedarray.cc index 3ff169781..1843effc8 100644 --- a/test/typedarray.cc +++ b/test/typedarray.cc @@ -184,6 +184,11 @@ Value GetTypedArrayLength(const CallbackInfo& info) { return Number::New(info.Env(), static_cast(array.ElementLength())); } +Value GetTypedArraySize(const CallbackInfo& info) { + TypedArray array = info[0].As(); + return Number::New(info.Env(), static_cast(array.ElementSize())); +} + Value GetTypedArrayBuffer(const CallbackInfo& info) { TypedArray array = info[0].As(); return array.ArrayBuffer(); @@ -287,6 +292,7 @@ Object InitTypedArray(Env env) { Function::New(env, CreateInvalidTypedArray); exports["getTypedArrayType"] = Function::New(env, GetTypedArrayType); exports["getTypedArrayLength"] = Function::New(env, GetTypedArrayLength); + exports["getTypedArraySize"] = Function::New(env, GetTypedArraySize); exports["getTypedArrayBuffer"] = Function::New(env, GetTypedArrayBuffer); exports["getTypedArrayElement"] = Function::New(env, GetTypedArrayElement); exports["setTypedArrayElement"] = Function::New(env, SetTypedArrayElement); diff --git a/test/typedarray.js b/test/typedarray.js index f1088814c..9c4b71288 100644 --- a/test/typedarray.js +++ b/test/typedarray.js @@ -6,15 +6,15 @@ module.exports = require('./common').runTest(test); function test (binding) { const testData = [ - ['int8', Int8Array], - ['uint8', Uint8Array], - ['uint8_clamped', Uint8ClampedArray], - ['int16', Int16Array], - ['uint16', Uint16Array], - ['int32', Int32Array], - ['uint32', Uint32Array], - ['float32', Float32Array], - ['float64', Float64Array] + ['int8', Int8Array, 1], + ['uint8', Uint8Array, 1], + ['uint8_clamped', Uint8ClampedArray, 1], + ['int16', Int16Array, 2], + ['uint16', Uint16Array, 2], + ['int32', Int32Array, 4], + ['uint32', Uint32Array, 4], + ['float32', Float32Array, 4], + ['float64', Float64Array, 8] ]; testData.forEach(data => { @@ -24,6 +24,7 @@ function test (binding) { assert.ok(t instanceof data[1]); assert.strictEqual(binding.typedarray.getTypedArrayType(t), data[0]); assert.strictEqual(binding.typedarray.getTypedArrayLength(t), length); + assert.strictEqual(binding.typedarray.getTypedArraySize(t), data[2]); t[3] = 11; assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 11); @@ -49,6 +50,7 @@ function test (binding) { assert.ok(t instanceof data[1]); assert.strictEqual(binding.typedarray.getTypedArrayType(t), data[0]); assert.strictEqual(binding.typedarray.getTypedArrayLength(t), length); + assert.strictEqual(binding.typedarray.getTypedArraySize(t), data[2]); t[3] = 11; assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 11); From f0b92563346cef9de78095fd8f877c6fcc51c25e Mon Sep 17 00:00:00 2001 From: Dante Calderon Date: Mon, 16 May 2022 23:19:40 -0500 Subject: [PATCH 2/3] Add tests for TypedArray#BufferLength --- test/typedarray.cc | 7 +++++++ test/typedarray.js | 2 ++ 2 files changed, 9 insertions(+) diff --git a/test/typedarray.cc b/test/typedarray.cc index 1843effc8..c76f6936a 100644 --- a/test/typedarray.cc +++ b/test/typedarray.cc @@ -189,6 +189,11 @@ Value GetTypedArraySize(const CallbackInfo& info) { return Number::New(info.Env(), static_cast(array.ElementSize())); } +Value GetTypedArrayByteLength(const CallbackInfo& info) { + TypedArray array = info[0].As(); + return Number::New(info.Env(), static_cast(array.ByteLength())); +} + Value GetTypedArrayBuffer(const CallbackInfo& info) { TypedArray array = info[0].As(); return array.ArrayBuffer(); @@ -293,6 +298,8 @@ Object InitTypedArray(Env env) { exports["getTypedArrayType"] = Function::New(env, GetTypedArrayType); exports["getTypedArrayLength"] = Function::New(env, GetTypedArrayLength); exports["getTypedArraySize"] = Function::New(env, GetTypedArraySize); + exports["getTypedArrayByteLength"] = + Function::New(env, GetTypedArrayByteLength); exports["getTypedArrayBuffer"] = Function::New(env, GetTypedArrayBuffer); exports["getTypedArrayElement"] = Function::New(env, GetTypedArrayElement); exports["setTypedArrayElement"] = Function::New(env, SetTypedArrayElement); diff --git a/test/typedarray.js b/test/typedarray.js index 9c4b71288..fdd2e5230 100644 --- a/test/typedarray.js +++ b/test/typedarray.js @@ -25,6 +25,7 @@ function test (binding) { assert.strictEqual(binding.typedarray.getTypedArrayType(t), data[0]); assert.strictEqual(binding.typedarray.getTypedArrayLength(t), length); assert.strictEqual(binding.typedarray.getTypedArraySize(t), data[2]); + assert.strictEqual(binding.typedarray.getTypedArrayByteLength(t), data[2] * length); t[3] = 11; assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 11); @@ -51,6 +52,7 @@ function test (binding) { assert.strictEqual(binding.typedarray.getTypedArrayType(t), data[0]); assert.strictEqual(binding.typedarray.getTypedArrayLength(t), length); assert.strictEqual(binding.typedarray.getTypedArraySize(t), data[2]); + assert.strictEqual(binding.typedarray.getTypedArrayByteLength(t), data[2] * length); t[3] = 11; assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 11); From bdc4c592144ef2265965af9d210910378efac9bb Mon Sep 17 00:00:00 2001 From: Dante Calderon Date: Mon, 16 May 2022 23:35:04 -0500 Subject: [PATCH 3/3] Add tests for TypedArray#ByteOffset --- test/typedarray.cc | 7 +++++++ test/typedarray.js | 2 ++ 2 files changed, 9 insertions(+) diff --git a/test/typedarray.cc b/test/typedarray.cc index c76f6936a..ae27ae317 100644 --- a/test/typedarray.cc +++ b/test/typedarray.cc @@ -189,6 +189,11 @@ Value GetTypedArraySize(const CallbackInfo& info) { return Number::New(info.Env(), static_cast(array.ElementSize())); } +Value GetTypedArrayByteOffset(const CallbackInfo& info) { + TypedArray array = info[0].As(); + return Number::New(info.Env(), static_cast(array.ByteOffset())); +} + Value GetTypedArrayByteLength(const CallbackInfo& info) { TypedArray array = info[0].As(); return Number::New(info.Env(), static_cast(array.ByteLength())); @@ -298,6 +303,8 @@ Object InitTypedArray(Env env) { exports["getTypedArrayType"] = Function::New(env, GetTypedArrayType); exports["getTypedArrayLength"] = Function::New(env, GetTypedArrayLength); exports["getTypedArraySize"] = Function::New(env, GetTypedArraySize); + exports["getTypedArrayByteOffset"] = + Function::New(env, GetTypedArrayByteOffset); exports["getTypedArrayByteLength"] = Function::New(env, GetTypedArrayByteLength); exports["getTypedArrayBuffer"] = Function::New(env, GetTypedArrayBuffer); diff --git a/test/typedarray.js b/test/typedarray.js index fdd2e5230..e32ba2274 100644 --- a/test/typedarray.js +++ b/test/typedarray.js @@ -25,6 +25,7 @@ function test (binding) { assert.strictEqual(binding.typedarray.getTypedArrayType(t), data[0]); assert.strictEqual(binding.typedarray.getTypedArrayLength(t), length); assert.strictEqual(binding.typedarray.getTypedArraySize(t), data[2]); + assert.strictEqual(binding.typedarray.getTypedArrayByteOffset(t), 0); assert.strictEqual(binding.typedarray.getTypedArrayByteLength(t), data[2] * length); t[3] = 11; @@ -52,6 +53,7 @@ function test (binding) { assert.strictEqual(binding.typedarray.getTypedArrayType(t), data[0]); assert.strictEqual(binding.typedarray.getTypedArrayLength(t), length); assert.strictEqual(binding.typedarray.getTypedArraySize(t), data[2]); + assert.strictEqual(binding.typedarray.getTypedArrayByteOffset(t), offset); assert.strictEqual(binding.typedarray.getTypedArrayByteLength(t), data[2] * length); t[3] = 11;