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,49 @@
#include <assert.h>
#include <stdlib.h>
#include "../../js-native-api/common.h"
#include "node_api.h"
#include "uv.h"
static int cleanup_hook_count = 0;
static void cleanup(void* arg) {
cleanup_hook_count++;
printf("cleanup(%d)\n", *(int*)(arg));
}
static int secret = 42;
static int wrong_secret = 17;
static void ObjectFinalizer(napi_env env, void* data, void* hint) {
// cleanup is called once.
assert(cleanup_hook_count == 1);
napi_ref* ref = data;
NODE_API_CALL_RETURN_VOID(env, napi_delete_reference(env, *ref));
free(ref);
}
static void CreateObjectWrap(napi_env env) {
napi_value js_obj;
napi_ref* ref = malloc(sizeof(*ref));
NODE_API_CALL_RETURN_VOID(env, napi_create_object(env, &js_obj));
NODE_API_CALL_RETURN_VOID(
env, napi_wrap(env, js_obj, ref, ObjectFinalizer, NULL, ref));
// create a strong reference so that the finalizer is called at shutdown.
NODE_API_CALL_RETURN_VOID(env, napi_reference_ref(env, *ref, NULL));
}
static napi_value Init(napi_env env, napi_value exports) {
// Create object wrap before cleanup hooks.
CreateObjectWrap(env);
napi_add_env_cleanup_hook(env, cleanup, &wrong_secret);
napi_add_env_cleanup_hook(env, cleanup, &secret);
napi_remove_env_cleanup_hook(env, cleanup, &wrong_secret);
// Create object wrap after cleanup hooks.
CreateObjectWrap(env);
return NULL;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)

View File

@ -0,0 +1,9 @@
{
'targets': [
{
'target_name': 'binding',
'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
'sources': [ 'binding.c' ]
}
]
}

View File

@ -0,0 +1,13 @@
'use strict';
const common = require('../../common');
const assert = require('assert');
const child_process = require('child_process');
if (process.argv[2] === 'child') {
require(`./build/${common.buildType}/binding`);
} else {
const { stdout, status, signal } =
child_process.spawnSync(process.execPath, [__filename, 'child']);
assert.strictEqual(status, 0, `process exited with status(${status}) and signal(${signal})`);
assert.strictEqual(stdout.toString().trim(), 'cleanup(42)');
}