File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,22 @@ Value GetFinalizeCount(const CallbackInfo& info) {
135135 return Number::New (info.Env (), finalizeCount);
136136}
137137
138+ Value CreateBufferWithConstructor (const CallbackInfo& info) {
139+ ArrayBuffer buffer = ArrayBuffer::New (info.Env (), testLength);
140+ if (buffer.ByteLength () != testLength) {
141+ Error::New (info.Env (), " Incorrect buffer length." ).ThrowAsJavaScriptException ();
142+ return Value ();
143+ }
144+ InitData (static_cast <uint8_t *>(buffer.Data ()), testLength);
145+ ArrayBuffer buffer2 (info.Env (), buffer);
146+ return buffer2;
147+ }
148+
149+ Value CheckEmptyBuffer (const CallbackInfo& info) {
150+ ArrayBuffer buffer;
151+ return Boolean::New (info.Env (), buffer.IsEmpty ());
152+ }
153+
138154} // end anonymous namespace
139155
140156Object InitArrayBuffer (Env env) {
@@ -148,6 +164,8 @@ Object InitArrayBuffer(Env env) {
148164 Function::New (env, CreateExternalBufferWithFinalizeHint);
149165 exports[" checkBuffer" ] = Function::New (env, CheckBuffer);
150166 exports[" getFinalizeCount" ] = Function::New (env, GetFinalizeCount);
167+ exports[" createBufferWithConstructor" ] = Function::New (env, CreateBufferWithConstructor);
168+ exports[" checkEmptyBuffer" ] = Function::New (env, CheckEmptyBuffer);
151169
152170 return exports;
153171}
Original file line number Diff line number Diff line change @@ -53,5 +53,13 @@ function test(binding) {
5353 global . gc ( ) ;
5454 assert . strictEqual ( 1 , binding . arraybuffer . getFinalizeCount ( ) ) ;
5555 } ,
56+
57+ 'ArrayBuffer with constructor' ,
58+ ( ) => {
59+ assert . strictEqual ( true , binding . arraybuffer . checkEmptyBuffer ( ) ) ;
60+ const test = binding . arraybuffer . createBufferWithConstructor ( ) ;
61+ binding . arraybuffer . checkBuffer ( test ) ;
62+ assert . ok ( test instanceof ArrayBuffer ) ;
63+ } ,
5664 ] ) ;
5765}
You can’t perform that action at this time.
0 commit comments