Skip to content

Commit

Permalink
node-api: define version 9
Browse files Browse the repository at this point in the history
PR-URL: #48151
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Gabriel Schulhof <gabrielschulhof@gmail.com>
  • Loading branch information
legendecas authored and MoLow committed Jul 6, 2023
1 parent e049ce2 commit ce7e6c6
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 23 deletions.
12 changes: 4 additions & 8 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1218,10 +1218,9 @@ This API throws a JavaScript `RangeError` with the text provided.
added:
- v17.2.0
- v16.14.0
napiVersion: 9
-->

> Stability: 1 - Experimental

```c
NAPI_EXTERN napi_status node_api_throw_syntax_error(napi_env env,
const char* code,
Expand Down Expand Up @@ -1339,10 +1338,9 @@ This API returns a JavaScript `RangeError` with the text provided.
added:
- v17.2.0
- v16.14.0
napiVersion: 9
-->

> Stability: 1 - Experimental

```c
NAPI_EXTERN napi_status node_api_create_syntax_error(napi_env env,
napi_value code,
Expand Down Expand Up @@ -2588,10 +2586,9 @@ of the ECMAScript Language Specification.

<!-- YAML
added: v17.5.0
napiVersion: 9
-->

> Stability: 1 - Experimental

```c
napi_status node_api_symbol_for(napi_env env,
const char* utf8description,
Expand Down Expand Up @@ -6344,10 +6341,9 @@ added:
- v15.9.0
- v14.18.0
- v12.22.0
napiVersion: 9
-->

> Stability: 1 - Experimental

```c
NAPI_EXTERN napi_status
node_api_get_module_file_name(napi_env env, const char** result);
Expand Down
12 changes: 6 additions & 6 deletions src/js_native_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_string_utf16(napi_env env,
NAPI_EXTERN napi_status NAPI_CDECL napi_create_symbol(napi_env env,
napi_value description,
napi_value* result);
#ifdef NAPI_EXPERIMENTAL
#if NAPI_VERSION >= 9
NAPI_EXTERN napi_status NAPI_CDECL
node_api_symbol_for(napi_env env,
const char* utf8description,
size_t length,
napi_value* result);
#endif // NAPI_EXPERIMENTAL
#endif // NAPI_VERSION >= 9
NAPI_EXTERN napi_status NAPI_CDECL napi_create_function(napi_env env,
const char* utf8name,
size_t length,
Expand All @@ -120,10 +120,10 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_range_error(napi_env env,
napi_value code,
napi_value msg,
napi_value* result);
#ifdef NAPI_EXPERIMENTAL
#if NAPI_VERSION >= 9
NAPI_EXTERN napi_status NAPI_CDECL node_api_create_syntax_error(
napi_env env, napi_value code, napi_value msg, napi_value* result);
#endif // NAPI_EXPERIMENTAL
#endif // NAPI_VERSION >= 9

// Methods to get the native napi_value from Primitive type
NAPI_EXTERN napi_status NAPI_CDECL napi_typeof(napi_env env,
Expand Down Expand Up @@ -378,11 +378,11 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_throw_type_error(napi_env env,
NAPI_EXTERN napi_status NAPI_CDECL napi_throw_range_error(napi_env env,
const char* code,
const char* msg);
#ifdef NAPI_EXPERIMENTAL
#if NAPI_VERSION >= 9
NAPI_EXTERN napi_status NAPI_CDECL node_api_throw_syntax_error(napi_env env,
const char* code,
const char* msg);
#endif // NAPI_EXPERIMENTAL
#endif // NAPI_VERSION >= 9
NAPI_EXTERN napi_status NAPI_CDECL napi_is_error(napi_env env,
napi_value value,
bool* result);
Expand Down
4 changes: 3 additions & 1 deletion src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -673,11 +673,13 @@ node::addon_context_register_func get_node_api_context_register_func(
const char* module_name,
int32_t module_api_version) {
static_assert(
NAPI_VERSION == 8,
NAPI_VERSION == 9,
"New version of Node-API requires adding another else-if statement below "
"for the new version and updating this assert condition.");
if (module_api_version <= NODE_API_DEFAULT_MODULE_API_VERSION) {
return node_api_context_register_func<NODE_API_DEFAULT_MODULE_API_VERSION>;
} else if (module_api_version == 9) {
return node_api_context_register_func<9>;
} else if (module_api_version == NAPI_VERSION_EXPERIMENTAL) {
return node_api_context_register_func<NAPI_VERSION_EXPERIMENTAL>;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/node_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ napi_remove_async_cleanup_hook(napi_async_cleanup_hook_handle remove_handle);

#endif // NAPI_VERSION >= 8

#ifdef NAPI_EXPERIMENTAL
#if NAPI_VERSION >= 9

NAPI_EXTERN napi_status NAPI_CDECL
node_api_get_module_file_name(napi_env env, const char** result);

#endif // NAPI_EXPERIMENTAL
#endif // NAPI_VERSION >= 9

EXTERN_C_END

Expand Down
2 changes: 1 addition & 1 deletion src/node_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

// The NAPI_VERSION provided by this version of the runtime. This is the version
// which the Node binary being built supports.
#define NAPI_VERSION 8
#define NAPI_VERSION 9

// Node API modules use NAPI_VERSION 8 by default if it is not explicitly
// specified. It must be always 8.
Expand Down
2 changes: 1 addition & 1 deletion test/js-native-api/test_error/test_error.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define NAPI_EXPERIMENTAL
#define NAPI_VERSION 9
#include <js_native_api.h>
#include "../common.h"

Expand Down
2 changes: 1 addition & 1 deletion test/js-native-api/test_general/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ assert.notStrictEqual(test_general.testGetPrototype(baseObject),
test_general.testGetPrototype(extendedObject));

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

[
123,
Expand Down
2 changes: 1 addition & 1 deletion test/js-native-api/test_properties/test_properties.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define NAPI_EXPERIMENTAL
#define NAPI_VERSION 9
#include <js_native_api.h>
#include "../common.h"

Expand Down
2 changes: 1 addition & 1 deletion test/js-native-api/test_reference/test_reference.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define NAPI_EXPERIMENTAL
#define NAPI_VERSION 9
#include <stdlib.h>
#include <assert.h>
#include <js_native_api.h>
Expand Down
2 changes: 1 addition & 1 deletion test/node-api/test_general/test_general.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define NAPI_EXPERIMENTAL
#define NAPI_VERSION 9
// we define NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED here to validate that it can
// be used as a form of test itself. It is
// not related to any of the other tests
Expand Down

0 comments on commit ce7e6c6

Please sign in to comment.