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,134 @@
#include "node.h"
#include <assert.h>
#include <vector>
namespace {
using node::AsyncResource;
using v8::External;
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::Integer;
using v8::Isolate;
using v8::Local;
using v8::MaybeLocal;
using v8::Object;
using v8::String;
using v8::Value;
int custom_async_resource_destructor_calls = 0;
class CustomAsyncResource : public AsyncResource {
public:
CustomAsyncResource(Isolate* isolate, Local<Object> resource)
: AsyncResource(isolate, resource, "CustomAsyncResource") {}
~CustomAsyncResource() {
custom_async_resource_destructor_calls++;
}
};
void CreateAsyncResource(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
assert(args[0]->IsObject());
AsyncResource* r;
if (args[1]->IsInt32()) {
r = new AsyncResource(isolate, args[0].As<Object>(), "foobär",
args[1].As<Integer>()->Value());
} else {
r = new AsyncResource(isolate, args[0].As<Object>(), "foobär");
}
args.GetReturnValue().Set(
External::New(isolate, static_cast<void*>(r)));
}
void DestroyAsyncResource(const FunctionCallbackInfo<Value>& args) {
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
delete r;
}
void CallViaFunction(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
Local<String> name =
String::NewFromUtf8(isolate, "methöd").ToLocalChecked();
Local<Value> fn =
r->get_resource()->Get(isolate->GetCurrentContext(), name)
.ToLocalChecked();
assert(fn->IsFunction());
Local<Value> arg = Integer::New(isolate, 42);
MaybeLocal<Value> ret = r->MakeCallback(fn.As<Function>(), 1, &arg);
args.GetReturnValue().Set(ret.FromMaybe(Local<Value>()));
}
void CallViaString(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
Local<String> name =
String::NewFromUtf8(isolate, "methöd").ToLocalChecked();
Local<Value> arg = Integer::New(isolate, 42);
MaybeLocal<Value> ret = r->MakeCallback(name, 1, &arg);
args.GetReturnValue().Set(ret.FromMaybe(Local<Value>()));
}
void CallViaUtf8Name(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
Local<Value> arg = Integer::New(isolate, 42);
MaybeLocal<Value> ret = r->MakeCallback("methöd", 1, &arg);
args.GetReturnValue().Set(ret.FromMaybe(Local<Value>()));
}
void GetAsyncId(const FunctionCallbackInfo<Value>& args) {
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
args.GetReturnValue().Set(r->get_async_id());
}
void GetTriggerAsyncId(const FunctionCallbackInfo<Value>& args) {
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
args.GetReturnValue().Set(r->get_trigger_async_id());
}
void GetResource(const FunctionCallbackInfo<Value>& args) {
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
args.GetReturnValue().Set(r->get_resource());
}
void RunSubclassTest(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Object> obj = Object::New(isolate);
assert(custom_async_resource_destructor_calls == 0);
CustomAsyncResource* resource = new CustomAsyncResource(isolate, obj);
delete static_cast<AsyncResource*>(resource);
assert(custom_async_resource_destructor_calls == 1);
}
void Initialize(Local<Object> exports) {
NODE_SET_METHOD(exports, "createAsyncResource", CreateAsyncResource);
NODE_SET_METHOD(exports, "destroyAsyncResource", DestroyAsyncResource);
NODE_SET_METHOD(exports, "callViaFunction", CallViaFunction);
NODE_SET_METHOD(exports, "callViaString", CallViaString);
NODE_SET_METHOD(exports, "callViaUtf8Name", CallViaUtf8Name);
NODE_SET_METHOD(exports, "getAsyncId", GetAsyncId);
NODE_SET_METHOD(exports, "getTriggerAsyncId", GetTriggerAsyncId);
NODE_SET_METHOD(exports, "getResource", GetResource);
NODE_SET_METHOD(exports, "runSubclassTest", RunSubclassTest);
}
} // anonymous namespace
NODE_MODULE(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,82 @@
'use strict';
const common = require('../../common');
const assert = require('assert');
const binding = require(`./build/${common.buildType}/binding`);
const async_hooks = require('async_hooks');
binding.runSubclassTest();
const kObjectTag = Symbol('kObjectTag');
const rootAsyncId = async_hooks.executionAsyncId();
const bindingUids = [];
let expectedTriggerId;
let before = 0;
let after = 0;
let destroy = 0;
async_hooks.createHook({
init(id, type, triggerAsyncId, resource) {
assert.strictEqual(typeof id, 'number');
assert.strictEqual(typeof resource, 'object');
assert(id > 1);
if (type === 'foobär') {
assert.strictEqual(resource.kObjectTag, kObjectTag);
assert.strictEqual(triggerAsyncId, expectedTriggerId);
bindingUids.push(id);
}
},
before(id) {
if (bindingUids.includes(id)) before++;
},
after(id) {
if (bindingUids.includes(id)) after++;
},
destroy(id) {
if (bindingUids.includes(id)) destroy++;
},
}).enable();
for (const call of [binding.callViaFunction,
binding.callViaString,
binding.callViaUtf8Name]) {
for (const passedTriggerId of [undefined, 12345]) {
let uid;
const object = {
methöd(arg) {
assert.strictEqual(this, object);
assert.strictEqual(arg, 42);
assert.strictEqual(async_hooks.executionAsyncId(), uid);
return 'baz';
},
kObjectTag,
};
if (passedTriggerId === undefined)
expectedTriggerId = rootAsyncId;
else
expectedTriggerId = passedTriggerId;
const resource = binding.createAsyncResource(object, passedTriggerId);
uid = bindingUids[bindingUids.length - 1];
const ret = call(resource);
assert.strictEqual(ret, 'baz');
assert.strictEqual(binding.getResource(resource), object);
assert.strictEqual(binding.getAsyncId(resource), uid);
assert.strictEqual(binding.getTriggerAsyncId(resource), expectedTriggerId);
binding.destroyAsyncResource(resource);
}
}
setImmediate(common.mustCall(() => {
assert.strictEqual(bindingUids.length, 6);
assert.strictEqual(before, bindingUids.length);
assert.strictEqual(after, bindingUids.length);
assert.strictEqual(destroy, bindingUids.length);
}));