diff --git a/packages/emnapi/include/node/js_native_api.h b/packages/emnapi/include/node/js_native_api.h index b2a66839..bb273320 100644 --- a/packages/emnapi/include/node/js_native_api.h +++ b/packages/emnapi/include/node/js_native_api.h @@ -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, @@ -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, diff --git a/packages/emnapi/include/node/node_api.h b/packages/emnapi/include/node/node_api.h index bd1c0a29..aa0bafd4 100644 --- a/packages/emnapi/include/node/node_api.h +++ b/packages/emnapi/include/node/node_api.h @@ -143,8 +143,7 @@ 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, @@ -152,7 +151,7 @@ node_api_create_buffer_from_arraybuffer(napi_env env, 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, diff --git a/packages/emnapi/src/life.ts b/packages/emnapi/src/life.ts index e10f4dad..65aa5c51 100644 --- a/packages/emnapi/src/life.ts +++ b/packages/emnapi/src/life.ts @@ -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) } diff --git a/packages/emnapi/src/macro.ts b/packages/emnapi/src/macro.ts index 10c1cfb5..7d44e9ef 100644 --- a/packages/emnapi/src/macro.ts +++ b/packages/emnapi/src/macro.ts @@ -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 ) diff --git a/packages/runtime/src/env.ts b/packages/runtime/src/env.ts index 29a99096..60c36266 100644 --- a/packages/runtime/src/env.ts +++ b/packages/runtime/src/env.ts @@ -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) { diff --git a/packages/runtime/src/typings/common.d.ts b/packages/runtime/src/typings/common.d.ts index d382e3ad..819cd1a2 100644 --- a/packages/runtime/src/typings/common.d.ts +++ b/packages/runtime/src/typings/common.d.ts @@ -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 } diff --git a/packages/test/CMakeLists.txt b/packages/test/CMakeLists.txt index 635c558a..77e35905 100644 --- a/packages/test/CMakeLists.txt +++ b/packages/test/CMakeLists.txt @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/packages/test/general/general.test.js b/packages/test/general/general.test.js index 000e2c95..4c1e005b 100644 --- a/packages/test/general/general.test.js +++ b/packages/test/general/general.test.js @@ -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, diff --git a/packages/test/runjs/binding.c b/packages/test/runjs/binding.c index 919d1d1e..890d2521 100644 --- a/packages/test/runjs/binding.c +++ b/packages/test/runjs/binding.c @@ -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 " @@ -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; @@ -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; }