2019-11-14 03:19:54 +08:00
|
|
|
#include <node.h>
|
|
|
|
#include <node_buffer.h>
|
|
|
|
#include <v8.h>
|
|
|
|
|
|
|
|
using v8::Context;
|
2019-11-20 04:34:44 +08:00
|
|
|
using v8::FunctionCallbackInfo;
|
2019-11-14 03:19:54 +08:00
|
|
|
using v8::Isolate;
|
|
|
|
using v8::Local;
|
|
|
|
using v8::Object;
|
|
|
|
using v8::Value;
|
|
|
|
|
2019-11-20 04:34:44 +08:00
|
|
|
uint32_t free_call_count = 0;
|
2019-11-14 03:19:54 +08:00
|
|
|
|
2019-11-20 04:34:44 +08:00
|
|
|
void GetFreeCallCount(const FunctionCallbackInfo<Value>& args) {
|
|
|
|
args.GetReturnValue().Set(free_call_count);
|
|
|
|
}
|
|
|
|
|
2019-11-14 03:19:54 +08:00
|
|
|
void Initialize(Local<Object> exports,
|
|
|
|
Local<Value> module,
|
|
|
|
Local<Context> context) {
|
|
|
|
Isolate* isolate = context->GetIsolate();
|
2019-11-20 04:34:44 +08:00
|
|
|
NODE_SET_METHOD(exports, "getFreeCallCount", GetFreeCallCount);
|
2019-12-04 06:22:08 +08:00
|
|
|
|
|
|
|
char* data = new char;
|
|
|
|
|
2019-11-14 03:19:54 +08:00
|
|
|
exports->Set(context,
|
|
|
|
v8::String::NewFromUtf8(
|
2020-07-08 04:03:17 +08:00
|
|
|
isolate, "buffer").ToLocalChecked(),
|
2019-11-14 03:19:54 +08:00
|
|
|
node::Buffer::New(
|
|
|
|
isolate,
|
|
|
|
data,
|
2020-04-28 10:53:52 +08:00
|
|
|
sizeof(char),
|
2019-11-20 04:34:44 +08:00
|
|
|
[](char* data, void* hint) {
|
2019-12-04 06:22:08 +08:00
|
|
|
delete data;
|
2019-11-20 04:34:44 +08:00
|
|
|
free_call_count++;
|
|
|
|
},
|
2019-11-14 03:19:54 +08:00
|
|
|
nullptr).ToLocalChecked()).Check();
|
|
|
|
}
|
|
|
|
|
|
|
|
NODE_MODULE_CONTEXT_AWARE(NODE_GYP_MODULE_NAME, Initialize)
|