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) {
135
135
return Number::New (info.Env (), finalizeCount);
136
136
}
137
137
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
+
138
154
} // end anonymous namespace
139
155
140
156
Object InitArrayBuffer (Env env) {
@@ -148,6 +164,8 @@ Object InitArrayBuffer(Env env) {
148
164
Function::New (env, CreateExternalBufferWithFinalizeHint);
149
165
exports[" checkBuffer" ] = Function::New (env, CheckBuffer);
150
166
exports[" getFinalizeCount" ] = Function::New (env, GetFinalizeCount);
167
+ exports[" createBufferWithConstructor" ] = Function::New (env, CreateBufferWithConstructor);
168
+ exports[" checkEmptyBuffer" ] = Function::New (env, CheckEmptyBuffer);
151
169
152
170
return exports;
153
171
}
Original file line number Diff line number Diff line change @@ -53,5 +53,13 @@ function test(binding) {
53
53
global . gc ( ) ;
54
54
assert . strictEqual ( 1 , binding . arraybuffer . getFinalizeCount ( ) ) ;
55
55
} ,
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
+ } ,
56
64
] ) ;
57
65
}
You can’t perform that action at this time.
0 commit comments