Skip to content

Commit

Permalink
Add tests for TypedArray#BufferOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
dantehemerson committed May 17, 2022
1 parent f0b9256 commit e5cc439
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 GetTypedArrayByteOffset(const CallbackInfo& info) {
TypedArray array = info[0].As<TypedArray>();
return Number::New(info.Env(), static_cast<double>(array.ByteOffset()));
}

Value GetTypedArrayByteLength(const CallbackInfo& info) {
TypedArray array = info[0].As<TypedArray>();
return Number::New(info.Env(), static_cast<double>(array.ByteLength()));
Expand Down Expand Up @@ -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);
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.getTypedArrayByteOffset(t), 0);
assert.strictEqual(binding.typedarray.getTypedArrayByteLength(t), data[2] * length);

t[3] = 11;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e5cc439

Please sign in to comment.