mirror of
https://github.com/nodejs/node.git
synced 2025-05-03 09:52:21 +00:00

PR-URL: https://github.com/nodejs/node/pull/22704 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
25 lines
630 B
C++
25 lines
630 B
C++
#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].As<v8::Integer>()->Value();
|
|
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)
|