Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,73 @@
#include <node.h>
#include <v8.h>
#include <uv.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
using v8::Context;
using v8::Function;
using v8::HandleScope;
using v8::Isolate;
using v8::Local;
using v8::MaybeLocal;
using v8::Object;
using v8::String;
using v8::Value;
size_t count = 0;
struct statically_allocated {
statically_allocated() {
assert(count == 0);
printf("ctor ");
}
~statically_allocated() {
assert(count == 0);
printf("dtor ");
}
} var;
void Dummy(void*) {
assert(0);
}
void Cleanup(void* str) {
printf("%s ", static_cast<const char*>(str));
// Check that calling into JS fails.
Isolate* isolate = Isolate::GetCurrent();
HandleScope handle_scope(isolate);
assert(isolate->InContext());
Local<Context> context = isolate->GetCurrentContext();
MaybeLocal<Value> call_result =
context->Global()->Get(
context, String::NewFromUtf8Literal(isolate, "Object"))
.ToLocalChecked().As<Function>()->Call(
context, v8::Null(isolate), 0, nullptr);
assert(call_result.IsEmpty());
}
void Initialize(Local<Object> exports,
Local<Value> module,
Local<Context> context) {
node::AddEnvironmentCleanupHook(
context->GetIsolate(),
Cleanup,
const_cast<void*>(static_cast<const void*>("cleanup")));
node::AddEnvironmentCleanupHook(context->GetIsolate(), Dummy, nullptr);
node::RemoveEnvironmentCleanupHook(context->GetIsolate(), Dummy, nullptr);
if (getenv("addExtraItemToEventLoop") != nullptr) {
// Add an item to the event loop that we do not clean up in order to make
// sure that for the main thread, this addon's memory persists even after
// the Environment instance has been destroyed.
static uv_async_t extra_async;
uv_loop_t* loop = node::GetCurrentEventLoop(context->GetIsolate());
int err = uv_async_init(loop, &extra_async, [](uv_async_t*) {});
assert(err == 0);
uv_unref(reinterpret_cast<uv_handle_t*>(&extra_async));
}
}
NODE_MODULE_CONTEXT_AWARE(NODE_GYP_MODULE_NAME, Initialize)

View File

@ -0,0 +1,9 @@
{
'targets': [
{
'target_name': 'binding',
'sources': [ 'binding.cc' ],
'includes': ['../common.gypi'],
}
]
}

View File

@ -0,0 +1,68 @@
'use strict';
const common = require('../../common');
const assert = require('assert');
const child_process = require('child_process');
const path = require('path');
const { Worker } = require('worker_threads');
const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`);
switch (process.argv[2]) {
case 'both':
require(binding);
// fallthrough
case 'worker-twice':
case 'worker': {
const worker = new Worker(`require(${JSON.stringify(binding)});`, {
eval: true,
});
if (process.argv[2] === 'worker-twice') {
worker.on('exit', common.mustCall(() => {
new Worker(`require(${JSON.stringify(binding)});`, {
eval: true,
});
}));
}
return;
}
case 'main-thread':
process.env.addExtraItemToEventLoop = 'yes';
require(binding);
return;
}
// Use process.report to figure out if we might be running under musl libc.
const glibc = process.report.getReport().header.glibcVersionRuntime;
assert(typeof glibc === 'string' || glibc === undefined, glibc);
const libcMayBeMusl = common.isLinux && glibc === undefined;
for (const { test, expected } of [
{ test: 'worker', expected: [ 'ctor cleanup dtor ' ] },
{ test: 'main-thread', expected: [ 'ctor cleanup dtor ' ] },
// We always only have 1 instance of the shared object in memory, so
// 1 ctor and 1 dtor call. If we attach the module to 2 Environments,
// we expect 2 cleanup calls, otherwise one.
{ test: 'both', expected: [ 'ctor cleanup cleanup dtor ' ] },
{
test: 'worker-twice',
// In this case, we load and unload an addon, then load and unload again.
// musl doesn't support unloading, so the output may be missing
// a dtor + ctor pair.
expected: [
'ctor cleanup dtor ctor cleanup dtor ',
].concat(libcMayBeMusl ? [
'ctor cleanup cleanup dtor ',
] : []),
},
]) {
console.log('spawning test', test);
const proc = child_process.spawnSync(process.execPath, [
__filename,
test,
]);
process.stderr.write(proc.stderr.toString());
assert.strictEqual(proc.stderr.toString(), '');
assert(expected.includes(proc.stdout.toString()),
`${proc.stdout.toString()} is not included in ${expected}`);
assert.strictEqual(proc.status, 0);
}