1 #include <node.h> 2 #include <node_buffer.h> 3 #include <v8.h> 4 5 #include <assert.h> 6 7 static int alive; 8 FreeCallback(char * data,void * hint)9static void FreeCallback(char* data, void* hint) { 10 assert(data == nullptr); 11 alive--; 12 } 13 Run(const v8::FunctionCallbackInfo<v8::Value> & args)14void Run(const v8::FunctionCallbackInfo<v8::Value>& args) { 15 v8::Isolate* isolate = args.GetIsolate(); 16 alive++; 17 18 { 19 v8::HandleScope scope(isolate); 20 v8::Local<v8::Object> buf = node::Buffer::New( 21 isolate, 22 nullptr, 23 0, 24 FreeCallback, 25 nullptr).ToLocalChecked(); 26 27 char* data = node::Buffer::Data(buf); 28 assert(data == nullptr); 29 } 30 31 isolate->RequestGarbageCollectionForTesting( 32 v8::Isolate::kFullGarbageCollection); 33 34 assert(alive == 0); 35 } 36 init(v8::Local<v8::Object> exports)37void init(v8::Local<v8::Object> exports) { 38 NODE_SET_METHOD(exports, "run", Run); 39 } 40 41 NODE_MODULE(NODE_GYP_MODULE_NAME, init) 42