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,58 @@
#include <node.h>
#include <node_buffer.h>
#include <assert.h>
namespace {
using v8::Context;
using v8::Isolate;
using v8::Local;
using v8::MaybeLocal;
using v8::Object;
using v8::Script;
using v8::String;
using v8::Value;
inline void MakeBufferInNewContext(
const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Context> context = Context::New(isolate);
Context::Scope context_scope(context);
// This should throw an exception, rather than actually do anything.
MaybeLocal<Object> buf = node::Buffer::Copy(isolate, "foo", 3);
assert(buf.IsEmpty());
}
inline void RunInNewContext(
const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Context> context = Context::New(isolate);
Context::Scope context_scope(context);
context->Global()->Set(
context,
String::NewFromUtf8(isolate, "data").ToLocalChecked(),
args[1]).FromJust();
assert(args[0]->IsString()); // source code
Local<Script> script;
Local<Value> ret;
if (!Script::Compile(context, args[0].As<String>()).ToLocal(&script) ||
!script->Run(context).ToLocal(&ret)) {
return;
}
args.GetReturnValue().Set(ret);
}
inline void Initialize(Local<Object> exports,
Local<Value> module,
Local<Context> context) {
NODE_SET_METHOD(exports, "runInNewContext", RunInNewContext);
NODE_SET_METHOD(exports, "makeBufferInNewContext", MakeBufferInNewContext);
}
} // anonymous namespace
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,23 @@
'use strict';
const common = require('../../common');
const assert = require('assert');
const {
makeBufferInNewContext,
} = require(`./build/${common.buildType}/binding`);
// Because the `Buffer` function and its prototype property only (currently)
// exist in a Node.js instances main context, trying to create buffers from
// another context throws an exception.
assert.throws(
() => makeBufferInNewContext(),
(exception) => {
assert.strictEqual(exception.constructor.name, 'Error');
assert(!(exception.constructor instanceof Error));
assert.strictEqual(exception.code, 'ERR_BUFFER_CONTEXT_NOT_AVAILABLE');
assert.strictEqual(exception.message,
'Buffer is not available for the current Context');
return true;
},
);

View File

@ -0,0 +1,17 @@
'use strict';
const common = require('../../common');
const assert = require('assert');
const { runInNewContext } = require(`./build/${common.buildType}/binding`);
const { performance } = require('perf_hooks');
// Check that performance.timerify() works when called from another context,
// for a function created in another context.
const check = runInNewContext(`
const { performance, assert } = data;
const timerified = performance.timerify(function() { return []; });
assert.strictEqual(timerified().constructor, Array);
'success';
`, { performance, assert });
assert.strictEqual(check, 'success');