diff --git a/test/arraybuffer.cc b/test/arraybuffer.cc index 27bb993fe..e46f8cba3 100644 --- a/test/arraybuffer.cc +++ b/test/arraybuffer.cc @@ -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(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) { @@ -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; } diff --git a/test/arraybuffer.js b/test/arraybuffer.js index d284fe84a..43604617f 100644 --- a/test/arraybuffer.js +++ b/test/arraybuffer.js @@ -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); + }, ]); }