Skip to content

Commit

Permalink
define version 10 (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi authored Jan 14, 2025
1 parent ecda026 commit fa24944
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 34 deletions.
8 changes: 2 additions & 6 deletions packages/emnapi/include/node/js_native_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_string_utf16(napi_env env,
const char16_t* str,
size_t length,
napi_value* result);
#ifdef NAPI_EXPERIMENTAL
#define NODE_API_EXPERIMENTAL_HAS_EXTERNAL_STRINGS
#if NAPI_VERSION >= 10
NAPI_EXTERN napi_status NAPI_CDECL node_api_create_external_string_latin1(
napi_env env,
char* str,
Expand All @@ -116,17 +115,14 @@ node_api_create_external_string_utf16(napi_env env,
void* finalize_hint,
napi_value* result,
bool* copied);
#endif // NAPI_EXPERIMENTAL

#ifdef NAPI_EXPERIMENTAL
#define NODE_API_EXPERIMENTAL_HAS_PROPERTY_KEYS
NAPI_EXTERN napi_status NAPI_CDECL node_api_create_property_key_latin1(
napi_env env, const char* str, size_t length, napi_value* result);
NAPI_EXTERN napi_status NAPI_CDECL node_api_create_property_key_utf8(
napi_env env, const char* str, size_t length, napi_value* result);
NAPI_EXTERN napi_status NAPI_CDECL node_api_create_property_key_utf16(
napi_env env, const char16_t* str, size_t length, napi_value* result);
#endif // NAPI_EXPERIMENTAL
#endif // NAPI_VERSION >= 10

NAPI_EXTERN napi_status NAPI_CDECL napi_create_symbol(napi_env env,
napi_value description,
Expand Down
5 changes: 2 additions & 3 deletions packages/emnapi/include/node/node_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,15 @@ napi_create_external_buffer(napi_env env,
napi_value* result);
#endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED

#ifdef NAPI_EXPERIMENTAL
#define NODE_API_EXPERIMENTAL_HAS_CREATE_BUFFER_FROM_ARRAYBUFFER
#if NAPI_VERSION >= 10

NAPI_EXTERN napi_status NAPI_CDECL
node_api_create_buffer_from_arraybuffer(napi_env env,
napi_value arraybuffer,
size_t byte_offset,
size_t byte_length,
napi_value* result);
#endif // NAPI_EXPERIMENTAL
#endif // NAPI_VERSION >= 10

NAPI_EXTERN napi_status NAPI_CDECL napi_create_buffer_copy(napi_env env,
size_t length,
Expand Down
2 changes: 1 addition & 1 deletion packages/emnapi/src/life.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function napi_create_reference (
$CHECK_ARG!(envObject, result)

const handle = emnapiCtx.handleStore.get(value)!
if (envObject.moduleApiVersion !== Version.NAPI_VERSION_EXPERIMENTAL) {
if (envObject.moduleApiVersion < 10) {
if (!(handle.isObject() || handle.isFunction() || handle.isSymbol())) {
return envObject.setLastError(napi_status.napi_invalid_arg)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/emnapi/src/macro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function $PREAMBLE (env: napi_env, fn: (envObject: Env) => napi_status):
$RETURN_STATUS_IF_FALSE!(
envObject,
envObject.canCallIntoJs(),
envObject.moduleApiVersion === Version.NAPI_VERSION_EXPERIMENTAL
envObject.moduleApiVersion >= 10
? napi_status.napi_cannot_run_js
: napi_status.napi_pending_exception
)
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class NodeEnv extends Env {
}
const hasProcess = typeof process === 'object' && process !== null
const hasForceFlag = hasProcess ? Boolean(process.execArgv && (process.execArgv.indexOf('--force-node-api-uncaught-exceptions-policy') !== -1)) : false
if (envObject.moduleApiVersion < NAPI_VERSION_EXPERIMENTAL && !hasForceFlag && !enforceUncaughtExceptionPolicy) {
if (envObject.moduleApiVersion < 10 && !hasForceFlag && !enforceUncaughtExceptionPolicy) {
const warn = hasProcess && typeof process.emitWarning === 'function'
? process.emitWarning
: function (warning: string | Error, type?: string, code?: string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/typings/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ declare const enum GlobalHandle {
declare const enum Version {
NODE_API_SUPPORTED_VERSION_MIN = 1,
NODE_API_DEFAULT_MODULE_API_VERSION = 8,
NODE_API_SUPPORTED_VERSION_MAX = 9,
NODE_API_SUPPORTED_VERSION_MAX = 10,
NAPI_VERSION_EXPERIMENTAL = 2147483647 // INT_MAX
}
14 changes: 7 additions & 7 deletions packages/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ add_test("tsfn2_st" "./tsfn2/binding.c" OFF)

if((NOT IS_WASM) OR IS_EMSCRIPTEN OR IS_WASI_THREADS)
add_test("string_mt" "./string/binding.c;./string/test_null.c" ON)
target_compile_definitions("string_mt" PRIVATE "NAPI_EXPERIMENTAL")
target_compile_definitions("string_mt" PRIVATE "NAPI_VERSION=10")
add_test("pool" "./pool/binding.c" ON)
add_test("tsfn" "./tsfn/binding.c" ON)
add_test("async_cleanup_hook" "./async_cleanup_hook/binding.c" ON)
Expand All @@ -268,7 +268,7 @@ add_test("fnfac" "./fnfac/binding.c" OFF)
add_test("general" "./general/binding.c" OFF)
add_test("filename" "./filename/binding.c" OFF)
add_test("string" "./string/binding.c;./string/test_null.c" OFF)
target_compile_definitions("string" PRIVATE "NAPI_EXPERIMENTAL")
target_compile_definitions("string" PRIVATE "NAPI_VERSION=10")
add_test("property" "./property/binding.c" OFF)
add_test("promise" "./promise/binding.c" OFF)
add_test("object" "./object/test_null.c;./object/test_object.c" OFF)
Expand Down Expand Up @@ -296,7 +296,7 @@ add_test("number" "./number/binding.c;./number/test_null.c" OFF)
add_test("symbol" "./symbol/binding.c" OFF)
add_test("typedarray" "./typedarray/binding.c" OFF)
add_test("buffer" "./buffer/binding.c" OFF)
target_compile_definitions("buffer" PRIVATE "NAPI_EXPERIMENTAL")
target_compile_definitions("buffer" PRIVATE "NAPI_VERSION=10")
add_test("buffer_finalizer" "./buffer_finalizer/binding.c" OFF)
add_test("fatal_exception" "./fatal_exception/binding.c" OFF)
add_test("cleanup_hook" "./cleanup_hook/binding.c" OFF)
Expand All @@ -305,14 +305,14 @@ add_test("finalizer" "./finalizer/binding.c" OFF)
target_compile_definitions("finalizer" PRIVATE "NAPI_EXPERIMENTAL")

add_test("reference_obj_only" "./ref_by_node_api_version/binding.c" OFF)
target_compile_definitions("reference_obj_only" PRIVATE "NAPI_VERSION=8")
target_compile_definitions("reference_obj_only" PRIVATE "NAPI_VERSION=9")
add_test("reference_all_types" "./ref_by_node_api_version/binding.c" OFF)
target_compile_definitions("reference_all_types" PRIVATE "NAPI_EXPERIMENTAL")
target_compile_definitions("reference_all_types" PRIVATE "NAPI_VERSION=10")

add_test("runjs_pe" "./runjs/binding.c" OFF)
target_compile_definitions("runjs_pe" PRIVATE "NAPI_VERSION=8")
target_compile_definitions("runjs_pe" PRIVATE "NAPI_VERSION=9")
add_test("runjs_cnrj" "./runjs/binding.c" OFF)
target_compile_definitions("runjs_cnrj" PRIVATE "NAPI_EXPERIMENTAL")
target_compile_definitions("runjs_cnrj" PRIVATE "NAPI_VERSION=10")

if(IS_WASM)
if(IS_EMSCRIPTEN)
Expand Down
2 changes: 1 addition & 1 deletion packages/test/general/general.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = load('general').then(async test_general => {
test_general.testGetPrototype(extendedObject))

// Test version management functions
assert.strictEqual(test_general.testGetVersion(), 9);
assert.strictEqual(test_general.testGetVersion(), 10);

[
123,
Expand Down
16 changes: 3 additions & 13 deletions packages/test/runjs/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static void Finalize(napi_env env, void* data, void* hint) {
// 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.
#ifdef NAPI_EXPERIMENTAL
#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 "
Expand All @@ -36,19 +36,10 @@ static void Finalize(napi_env env, void* data, void* hint) {
result == napi_pending_exception || result == napi_ok,
"getting named property from global in finalizer should succeed "
"or return napi_pending_exception");
#endif // NAPI_EXPERIMENTAL
#endif // NAPI_VERSION > 9
free(ref);
}

static void BasicFinalize(node_api_basic_env env, void* data, void* hint) {
#ifdef NAPI_EXPERIMENTAL
NODE_API_BASIC_CALL_RETURN_VOID(
env, node_api_post_finalizer(env, Finalize, data, hint));
#else
Finalize(env, data, hint);
#endif
}

static napi_value CreateRef(napi_env env, napi_callback_info info) {
size_t argc = 1;
napi_value cb;
Expand All @@ -59,8 +50,7 @@ static napi_value CreateRef(napi_env env, napi_callback_info info) {
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, BasicFinalize, NULL, ref));
NODE_API_CALL(env, napi_add_finalizer(env, cb, ref, Finalize, NULL, ref));
return cb;
}

Expand Down

0 comments on commit fa24944

Please sign in to comment.