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,8 @@
{
"targets": [
{
"target_name": "test_worker_terminate_finalization",
"sources": [ "test_worker_terminate_finalization.c" ]
}
]
}

View File

@ -0,0 +1,23 @@
'use strict';
const common = require('../../common');
// Refs: https://github.com/nodejs/node/issues/34731
// Refs: https://github.com/nodejs/node/pull/35777
// Refs: https://github.com/nodejs/node/issues/35778
const { Worker, isMainThread } = require('worker_threads');
if (isMainThread) {
const worker = new Worker(__filename);
worker.on('error', common.mustNotCall());
} else {
const { Test } =
require(`./build/${common.buildType}/test_worker_terminate_finalization`);
// Spin up thread and call add-on create the right sequence
// of rerences to hit the case reported in
// https://github.com/nodejs/node-addon-api/issues/722
// will crash if run under debug and its not possible to
// create object in the specific finalizer
Test(new Object());
}

View File

@ -0,0 +1,51 @@
#include <stdio.h>
#include <node_api.h>
#include <assert.h>
#include <stdlib.h>
#include "../../js-native-api/common.h"
#define BUFFER_SIZE 4
int wrappedNativeData;
napi_ref ref;
void WrapFinalizer(napi_env env, void* data, void* hint) {
uint32_t count;
NODE_API_CALL_RETURN_VOID(env, napi_reference_unref(env, ref, &count));
NODE_API_CALL_RETURN_VOID(env, napi_delete_reference(env, ref));
}
void BufferFinalizer(napi_env env, void* data, void* hint) {
free(hint);
}
napi_value Test(napi_env env, napi_callback_info info) {
size_t argc = 1;
napi_value argv[1];
napi_value result;
void* bufferData = malloc(BUFFER_SIZE);
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL));
NODE_API_CALL(env,
napi_create_external_buffer(
env, BUFFER_SIZE, bufferData, BufferFinalizer, bufferData, &result));
NODE_API_CALL(env, napi_create_reference(env, result, 1, &ref));
NODE_API_CALL(env,
napi_wrap(
env, argv[0], (void*) &wrappedNativeData, WrapFinalizer, NULL, NULL));
return NULL;
}
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor properties[] = {
DECLARE_NODE_API_PROPERTY("Test", Test)
};
NODE_API_CALL(env, napi_define_properties(
env, exports, sizeof(properties) / sizeof(*properties), properties));
return exports;
}
// Do not start using NAPI_MODULE_INIT() here, so that we can test
// compatibility of Workers with NAPI_MODULE().
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)