Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions test/typedarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@ Value GetTypedArrayLength(const CallbackInfo& info) {
return Number::New(info.Env(), static_cast<double>(array.ElementLength()));
}

Value GetTypedArraySize(const CallbackInfo& info) {
TypedArray array = info[0].As<TypedArray>();
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()));
}

Value GetTypedArrayBuffer(const CallbackInfo& info) {
TypedArray array = info[0].As<TypedArray>();
return array.ArrayBuffer();
Expand Down Expand Up @@ -287,6 +302,11 @@ 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["getTypedArrayByteOffset"] =
Function::New(env, GetTypedArrayByteOffset);
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
24 changes: 15 additions & 9 deletions test/typedarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Comment on lines +9 to +17
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

];

testData.forEach(data => {
Expand All @@ -24,6 +24,9 @@ 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]);
assert.strictEqual(binding.typedarray.getTypedArrayByteOffset(t), 0);
assert.strictEqual(binding.typedarray.getTypedArrayByteLength(t), data[2] * length);

t[3] = 11;
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 11);
Expand All @@ -49,6 +52,9 @@ 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]);
assert.strictEqual(binding.typedarray.getTypedArrayByteOffset(t), offset);
assert.strictEqual(binding.typedarray.getTypedArrayByteLength(t), data[2] * length);

t[3] = 11;
assert.strictEqual(binding.typedarray.getTypedArrayElement(t, 3), 11);
Expand Down