2015-11-02 08:34:19 +08:00
|
|
|
#include <node.h>
|
|
|
|
#include <node_buffer.h>
|
|
|
|
#include <v8.h>
|
|
|
|
|
2016-06-20 16:46:38 +08:00
|
|
|
#include <assert.h>
|
|
|
|
|
2015-11-02 08:34:19 +08:00
|
|
|
static int alive;
|
|
|
|
|
|
|
|
static void FreeCallback(char* data, void* hint) {
|
2016-06-20 16:46:38 +08:00
|
|
|
assert(data == nullptr);
|
2015-11-02 08:34:19 +08:00
|
|
|
alive--;
|
|
|
|
}
|
|
|
|
|
2020-05-09 12:41:58 +08:00
|
|
|
void IsAlive(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
|
|
args.GetReturnValue().Set(alive);
|
|
|
|
}
|
|
|
|
|
2015-11-02 08:34:19 +08:00
|
|
|
void Run(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
|
|
v8::Isolate* isolate = args.GetIsolate();
|
|
|
|
alive++;
|
|
|
|
|
|
|
|
{
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
v8::Local<v8::Object> buf = node::Buffer::New(
|
|
|
|
isolate,
|
|
|
|
nullptr,
|
|
|
|
0,
|
|
|
|
FreeCallback,
|
|
|
|
nullptr).ToLocalChecked();
|
|
|
|
|
|
|
|
char* data = node::Buffer::Data(buf);
|
2016-06-20 16:46:38 +08:00
|
|
|
assert(data == nullptr);
|
2015-11-02 08:34:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-18 00:53:40 +08:00
|
|
|
void init(v8::Local<v8::Object> exports) {
|
|
|
|
NODE_SET_METHOD(exports, "run", Run);
|
2020-05-09 12:41:58 +08:00
|
|
|
NODE_SET_METHOD(exports, "isAlive", IsAlive);
|
2015-11-02 08:34:19 +08:00
|
|
|
}
|
|
|
|
|
2017-09-06 04:53:06 +08:00
|
|
|
NODE_MODULE(NODE_GYP_MODULE_NAME, init)
|