Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add TypedArray ElementSize, ByteLength and ByteOffset tests #1179

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions test/typedarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ 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 GetTypedArrayBuffer(const CallbackInfo& info) {
TypedArray array = info[0].As<TypedArray>();
return array.ArrayBuffer();
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 11 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
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,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);
Expand All @@ -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);
Expand Down