11cb0ef41Sopenharmony_ci#include <node.h> 21cb0ef41Sopenharmony_ci#include <node_buffer.h> 31cb0ef41Sopenharmony_ci#include <v8.h> 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciusing v8::Context; 61cb0ef41Sopenharmony_ciusing v8::FunctionCallbackInfo; 71cb0ef41Sopenharmony_ciusing v8::Isolate; 81cb0ef41Sopenharmony_ciusing v8::Local; 91cb0ef41Sopenharmony_ciusing v8::Object; 101cb0ef41Sopenharmony_ciusing v8::Value; 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciuint32_t free_call_count = 0; 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_civoid GetFreeCallCount(const FunctionCallbackInfo<Value>& args) { 151cb0ef41Sopenharmony_ci args.GetReturnValue().Set(free_call_count); 161cb0ef41Sopenharmony_ci} 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_civoid Initialize(Local<Object> exports, 191cb0ef41Sopenharmony_ci Local<Value> module, 201cb0ef41Sopenharmony_ci Local<Context> context) { 211cb0ef41Sopenharmony_ci Isolate* isolate = context->GetIsolate(); 221cb0ef41Sopenharmony_ci NODE_SET_METHOD(exports, "getFreeCallCount", GetFreeCallCount); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci char* data = new char; 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci exports->Set(context, 271cb0ef41Sopenharmony_ci v8::String::NewFromUtf8( 281cb0ef41Sopenharmony_ci isolate, "buffer").ToLocalChecked(), 291cb0ef41Sopenharmony_ci node::Buffer::New( 301cb0ef41Sopenharmony_ci isolate, 311cb0ef41Sopenharmony_ci data, 321cb0ef41Sopenharmony_ci sizeof(char), 331cb0ef41Sopenharmony_ci [](char* data, void* hint) { 341cb0ef41Sopenharmony_ci delete data; 351cb0ef41Sopenharmony_ci free_call_count++; 361cb0ef41Sopenharmony_ci }, 371cb0ef41Sopenharmony_ci nullptr).ToLocalChecked()).Check(); 381cb0ef41Sopenharmony_ci} 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ciNODE_MODULE_CONTEXT_AWARE(NODE_GYP_MODULE_NAME, Initialize) 41