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 arraybuffer tests #369

Closed
wants to merge 1 commit into from
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
18 changes: 18 additions & 0 deletions test/arraybuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ Value GetFinalizeCount(const CallbackInfo& info) {
return Number::New(info.Env(), finalizeCount);
}

Value CreateBufferWithConstructor(const CallbackInfo& info) {
ArrayBuffer buffer = ArrayBuffer::New(info.Env(), testLength);
if (buffer.ByteLength() != testLength) {
Error::New(info.Env(), "Incorrect buffer length.").ThrowAsJavaScriptException();
return Value();
}
InitData(static_cast<uint8_t*>(buffer.Data()), testLength);
ArrayBuffer buffer2(info.Env(), buffer);
return buffer2;
}

Value CheckEmptyBuffer(const CallbackInfo& info) {
ArrayBuffer buffer;
return Boolean::New(info.Env(), buffer.IsEmpty());
}

} // end anonymous namespace

Object InitArrayBuffer(Env env) {
Expand All @@ -148,6 +164,8 @@ Object InitArrayBuffer(Env env) {
Function::New(env, CreateExternalBufferWithFinalizeHint);
exports["checkBuffer"] = Function::New(env, CheckBuffer);
exports["getFinalizeCount"] = Function::New(env, GetFinalizeCount);
exports["createBufferWithConstructor"] = Function::New(env, CreateBufferWithConstructor);
exports["checkEmptyBuffer"] = Function::New(env, CheckEmptyBuffer);

return exports;
}
8 changes: 8 additions & 0 deletions test/arraybuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,13 @@ function test(binding) {
global.gc();
assert.strictEqual(1, binding.arraybuffer.getFinalizeCount());
},

'ArrayBuffer with constructor',
() => {
assert.strictEqual(true, binding.arraybuffer.checkEmptyBuffer());
const test = binding.arraybuffer.createBufferWithConstructor();
binding.arraybuffer.checkBuffer(test);
assert.ok(test instanceof ArrayBuffer);
},
]);
}