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,18 @@
{
"targets": [
{
"target_name": "test_cannot_run_js",
"sources": [
"test_cannot_run_js.c"
],
"defines": [ "NAPI_VERSION=10" ],
},
{
"target_name": "test_pending_exception",
"sources": [
"test_cannot_run_js.c"
],
"defines": [ "NAPI_VERSION=9" ],
}
]
}

View File

@ -0,0 +1,24 @@
'use strict';
// Test that `napi_call_function()` returns `napi_cannot_run_js` in experimental
// mode and `napi_pending_exception` otherwise. This test calls the add-on's
// `createRef()` method, which creates a strong reference to a JS function. When
// the process exits, it calls all reference finalizers. The finalizer for the
// strong reference created herein will attempt to call `napi_get_property()` on
// a property of the global object and will abort the process if the API doesn't
// return the correct status.
const { buildType, mustNotCall } = require('../../common');
const addon_v8 = require(`./build/${buildType}/test_pending_exception`);
const addon_new = require(`./build/${buildType}/test_cannot_run_js`);
function runTests(addon, isVersion8) {
addon.createRef(mustNotCall());
}
function runAllTests() {
runTests(addon_v8, /* isVersion8 */ true);
runTests(addon_new, /* isVersion8 */ false);
}
runAllTests();

View File

@ -0,0 +1,66 @@
#include <js_native_api.h>
#include "../common.h"
#include "../entry_point.h"
#include "stdlib.h"
static void Finalize(napi_env env, void* data, void* hint) {
napi_value global, set_timeout;
napi_ref* ref = data;
NODE_API_BASIC_ASSERT_RETURN_VOID(
napi_delete_reference(env, *ref) == napi_ok,
"deleting reference in finalizer should succeed");
NODE_API_BASIC_ASSERT_RETURN_VOID(
napi_get_global(env, &global) == napi_ok,
"getting global reference in finalizer should succeed");
napi_status result =
napi_get_named_property(env, global, "setTimeout", &set_timeout);
// The finalizer could be invoked either from check callbacks (as native
// immediates) if the event loop is still running (where napi_ok is returned)
// or during environment shutdown (where napi_cannot_run_js or
// napi_pending_exception is returned). This is not deterministic from
// the point of view of the addon.
#if NAPI_VERSION > 9
NODE_API_BASIC_ASSERT_RETURN_VOID(
result == napi_cannot_run_js || result == napi_ok,
"getting named property from global in finalizer should succeed "
"or return napi_cannot_run_js");
#else
NODE_API_BASIC_ASSERT_RETURN_VOID(
result == napi_pending_exception || result == napi_ok,
"getting named property from global in finalizer should succeed "
"or return napi_pending_exception");
#endif // NAPI_VERSION > 9
free(ref);
}
static napi_value CreateRef(napi_env env, napi_callback_info info) {
size_t argc = 1;
napi_value cb;
napi_valuetype value_type;
napi_ref* ref = malloc(sizeof(*ref));
NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, &cb, NULL, NULL));
NODE_API_ASSERT(env, argc == 1, "Function takes only one argument");
NODE_API_CALL(env, napi_typeof(env, cb, &value_type));
NODE_API_ASSERT(
env, value_type == napi_function, "argument must be function");
NODE_API_CALL(env, napi_add_finalizer(env, cb, ref, Finalize, NULL, ref));
return cb;
}
EXTERN_C_START
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor properties[] = {
DECLARE_NODE_API_PROPERTY("createRef", CreateRef),
};
NODE_API_CALL(
env,
napi_define_properties(
env, exports, sizeof(properties) / sizeof(*properties), properties));
return exports;
}
EXTERN_C_END