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': 'binding',
'sources': [ 'test_worker_buffer_callback.c' ]
}
]
}

View File

@ -0,0 +1,17 @@
'use strict';
const common = require('../../common');
const path = require('path');
const assert = require('assert');
const { Worker } = require('worker_threads');
const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`);
const { getFreeCallCount } = require(binding);
// Test that buffers allocated with a free callback through our APIs are
// released when a Worker owning it exits.
const w = new Worker(`require(${JSON.stringify(binding)})`, { eval: true });
assert.strictEqual(getFreeCallCount(), 0);
w.on('exit', common.mustCall(() => {
assert.strictEqual(getFreeCallCount(), 1);
}));

View File

@ -0,0 +1,18 @@
'use strict';
const common = require('../../common');
const assert = require('assert');
const { MessageChannel } = require('worker_threads');
const { buffer } = require(`./build/${common.buildType}/binding`);
// Test that buffers allocated with a free callback through our APIs are not
// transferred.
const { port1 } = new MessageChannel();
const origByteLength = buffer.byteLength;
assert.throws(() => port1.postMessage(buffer, [buffer]), {
code: 25,
name: 'DataCloneError',
});
assert.strictEqual(buffer.byteLength, origByteLength);
assert.notStrictEqual(buffer.byteLength, 0);

View File

@ -0,0 +1,46 @@
#include <stdio.h>
#include <stdlib.h>
#include <node_api.h>
#include <assert.h>
#include "../../js-native-api/common.h"
uint32_t free_call_count = 0;
napi_value GetFreeCallCount(napi_env env, napi_callback_info info) {
napi_value value;
NODE_API_CALL(env, napi_create_uint32(env, free_call_count, &value));
return value;
}
static void finalize_cb(napi_env env, void* finalize_data, void* hint) {
free(finalize_data);
free_call_count++;
}
NAPI_MODULE_INIT() {
napi_property_descriptor properties[] = {
DECLARE_NODE_API_PROPERTY("getFreeCallCount", GetFreeCallCount)
};
NODE_API_CALL(env, napi_define_properties(
env, exports, sizeof(properties) / sizeof(*properties), properties));
// This is a slight variation on the non-N-API test: We create an ArrayBuffer
// rather than a Node.js Buffer, since testing the latter would only test
// the same code paths and not the ones specific to N-API.
napi_value buffer;
char* data = malloc(sizeof(char));
NODE_API_CALL(env, napi_create_external_arraybuffer(
env,
data,
sizeof(char),
finalize_cb,
NULL,
&buffer));
NODE_API_CALL(env, napi_set_named_property(env, exports, "buffer", buffer));
return exports;
}