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,40 @@
#include <node.h>
#include <node_buffer.h>
#include <v8.h>
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::Value;
uint32_t free_call_count = 0;
void GetFreeCallCount(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(free_call_count);
}
void Initialize(Local<Object> exports,
Local<Value> module,
Local<Context> context) {
Isolate* isolate = context->GetIsolate();
NODE_SET_METHOD(exports, "getFreeCallCount", GetFreeCallCount);
char* data = new char;
exports->Set(context,
v8::String::NewFromUtf8(
isolate, "buffer").ToLocalChecked(),
node::Buffer::New(
isolate,
data,
sizeof(char),
[](char* data, void* hint) {
delete data;
free_call_count++;
},
nullptr).ToLocalChecked()).Check();
}
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,19 @@
'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);
// getFreeCallCount initial value is 0
assert.strictEqual(getFreeCallCount(), 0);
// 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 });
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.buffer]), {
code: 25,
name: 'DataCloneError',
});
assert.strictEqual(buffer.byteLength, origByteLength);
assert.notStrictEqual(buffer.byteLength, 0);