1#include <node.h> 2#include <node_buffer.h> 3#include <v8.h> 4 5using v8::Context; 6using v8::FunctionCallbackInfo; 7using v8::Isolate; 8using v8::Local; 9using v8::Object; 10using v8::Value; 11 12uint32_t free_call_count = 0; 13 14void GetFreeCallCount(const FunctionCallbackInfo<Value>& args) { 15 args.GetReturnValue().Set(free_call_count); 16} 17 18void Initialize(Local<Object> exports, 19 Local<Value> module, 20 Local<Context> context) { 21 Isolate* isolate = context->GetIsolate(); 22 NODE_SET_METHOD(exports, "getFreeCallCount", GetFreeCallCount); 23 24 char* data = new char; 25 26 exports->Set(context, 27 v8::String::NewFromUtf8( 28 isolate, "buffer").ToLocalChecked(), 29 node::Buffer::New( 30 isolate, 31 data, 32 sizeof(char), 33 [](char* data, void* hint) { 34 delete data; 35 free_call_count++; 36 }, 37 nullptr).ToLocalChecked()).Check(); 38} 39 40NODE_MODULE_CONTEXT_AWARE(NODE_GYP_MODULE_NAME, Initialize) 41