mirror of
https://github.com/nodejs/node.git
synced 2025-05-22 00:43:56 +00:00

Currently the nm_modname does not match the file name of the resulting module. In fact, the nm_modname is pretty arbitrary. This seeks to introduce some consistency into the nm_modname property by having the name of the module appear in exactly one place: the "target_name" property of the gyp target that builds the module. PR-URL: https://github.com/nodejs/node/pull/15209 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
#include <node.h>
|
|
#include <node_buffer.h>
|
|
#include <v8.h>
|
|
|
|
#include <assert.h>
|
|
|
|
static int alive;
|
|
static char buf[1024];
|
|
|
|
static void FreeCallback(char* data, void* hint) {
|
|
alive--;
|
|
}
|
|
|
|
void Alloc(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
v8::Isolate* isolate = args.GetIsolate();
|
|
alive++;
|
|
|
|
uintptr_t alignment = args[1]->IntegerValue();
|
|
uintptr_t offset = args[2]->IntegerValue();
|
|
|
|
uintptr_t static_offset = reinterpret_cast<uintptr_t>(buf) % alignment;
|
|
char* aligned = buf + (alignment - static_offset) + offset;
|
|
|
|
args.GetReturnValue().Set(node::Buffer::New(
|
|
isolate,
|
|
aligned,
|
|
args[0]->IntegerValue(),
|
|
FreeCallback,
|
|
nullptr).ToLocalChecked());
|
|
}
|
|
|
|
void Check(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
v8::Isolate* isolate = args.GetIsolate();
|
|
isolate->RequestGarbageCollectionForTesting(
|
|
v8::Isolate::kFullGarbageCollection);
|
|
assert(alive > 0);
|
|
}
|
|
|
|
void init(v8::Local<v8::Object> exports) {
|
|
NODE_SET_METHOD(exports, "alloc", Alloc);
|
|
NODE_SET_METHOD(exports, "check", Check);
|
|
}
|
|
|
|
NODE_MODULE(NODE_GYP_MODULE_NAME, init)
|