From f0b92563346cef9de78095fd8f877c6fcc51c25e Mon Sep 17 00:00:00 2001 From: Dante Calderon Date: Mon, 16 May 2022 23:19:40 -0500 Subject: [PATCH] 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);