Skip to content

Commit

Permalink
Add tests for TypedArray#BufferLength
Browse files Browse the repository at this point in the history
  • Loading branch information
dantehemerson committed May 17, 2022
1 parent b2bc53b commit f0b9256
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/typedarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ Value GetTypedArraySize(const CallbackInfo& info) {
return Number::New(info.Env(), static_cast<double>(array.ElementSize()));
}

Value GetTypedArrayByteLength(const CallbackInfo& info) {
TypedArray array = info[0].As<TypedArray>();
return Number::New(info.Env(), static_cast<double>(array.ByteLength()));
}

Value GetTypedArrayBuffer(const CallbackInfo& info) {
TypedArray array = info[0].As<TypedArray>();
return array.ArrayBuffer();
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions test/typedarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit f0b9256

Please sign in to comment.