blob: 628a6b691376b3ffebbd30f5597301f614478e6b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#include <stdlib.h>
#include <node.h>
#include <v8.h>
void EnsureAllocation(const v8::FunctionCallbackInfo<v8::Value> &args) {
v8::Isolate* isolate = args.GetIsolate();
uintptr_t size = args[0]->IntegerValue();
v8::Local<v8::Boolean> success;
void* buffer = malloc(size);
if (buffer) {
success = v8::Boolean::New(isolate, true);
free(buffer);
} else {
success = v8::Boolean::New(isolate, false);
}
args.GetReturnValue().Set(success);
}
void init(v8::Local<v8::Object> exports) {
NODE_SET_METHOD(exports, "ensureAllocation", EnsureAllocation);
}
NODE_MODULE(NODE_GYP_MODULE_NAME, init)
|