From cec166e85f32e02fc0789943cabf94abad415c92 Mon Sep 17 00:00:00 2001 From: Kyle Farnung Date: Thu, 7 Dec 2017 15:01:13 -0800 Subject: [PATCH] n-api: restrict exports by version * Move `napi_get_uv_event_loop` into the `NAPI_VERSION >= 2` section * Move `napi_open_callback_scope`, `napi_close_callback_scope`, `napi_fatal_exception`, `napi_add_env_cleanup_hook`, and `napi_remove_env_cleanup_hook` into the `NAPI_VERSION >= 3` section * Added a missing `added` property to `napi_get_uv_event_loop` in the docs * Added a `napiVersion` property to the docs and updated the parser and generator to use it. * Added usage documentation PR-URL: https://github.com/nodejs/node/pull/19962 Reviewed-By: Gabriel Schulhof Reviewed-By: Michael Dawson --- doc/api/n-api.md | 162 +++++++++++++++++++++++++++++++++++++++++++- src/node_api.h | 55 ++++++++++----- tools/doc/common.js | 4 ++ tools/doc/html.js | 4 ++ 4 files changed, 207 insertions(+), 18 deletions(-) diff --git a/doc/api/n-api.md b/doc/api/n-api.md index 0d3fdc3a078167..982b15f496893b 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -42,6 +42,8 @@ for the N-API C based functions exported by Node.js. These wrappers are not part of N-API, nor will they be maintained as part of Node.js. One such example is: [node-addon-api](https://github.com/nodejs/node-addon-api). +## Usage + In order to use the N-API functions, include the file [`node_api.h`](https://github.com/nodejs/node/blob/master/src/node_api.h) which is located in the src directory in the node development tree: @@ -50,6 +52,41 @@ which is located in the src directory in the node development tree: #include ``` +This will opt into the default `NAPI_VERSION` for the given release of Node.js. +In order to ensure compatibility with specific versions of N-API, the version +can be specified explicitly when including the header: + +```C +#define NAPI_VERSION 3 +#include +``` + +This restricts the N-API surface to just the functionality that was available in +the specified (and earlier) versions. + +Some of the N-API surface is considered experimental and requires explicit +opt-in to access those APIs: + +```C +#define NAPI_EXPERIMENTAL +#include +``` + +In this case the entire API surface, including any experimental APIs, will be +available to the module code. + +## N-API Version Matrix + +| | 1 | 2 | 3 | +|:-----:|:-------:|:--------:|:--------:| +| v4.x | | | | +| v6.x | | | v6.14.2* | +| v8.x | v8.0.0* | v8.10.0* | | +| v9.x | v9.0.0* | v9.3.0* | v9.11.0* | +| v10.x | | | v10.0.0 | + +\* Indicates that the N-API version was released as experimental + ## Basic N-API Data Types N-API exposes the following fundamental datatypes as abstractions that are @@ -326,6 +363,7 @@ logging purposes. #### napi_get_last_error_info ```C napi_status @@ -424,6 +462,7 @@ TypeError [ERR_ERROR_1] #### napi_throw ```C NAPI_EXTERN napi_status napi_throw(napi_env env, napi_value error); @@ -438,6 +477,7 @@ This API throws the JavaScript value provided. #### napi_throw_error ```C NAPI_EXTERN napi_status napi_throw_error(napi_env env, @@ -456,6 +496,7 @@ This API throws a JavaScript `Error` with the text provided. #### napi_throw_type_error ```C NAPI_EXTERN napi_status napi_throw_type_error(napi_env env, @@ -474,6 +515,7 @@ This API throws a JavaScript `TypeError` with the text provided. #### napi_throw_range_error ```C NAPI_EXTERN napi_status napi_throw_range_error(napi_env env, @@ -492,6 +534,7 @@ This API throws a JavaScript `RangeError` with the text provided. #### napi_is_error ```C NAPI_EXTERN napi_status napi_is_error(napi_env env, @@ -510,6 +553,7 @@ This API queries a `napi_value` to check if it represents an error object. #### napi_create_error ```C NAPI_EXTERN napi_status napi_create_error(napi_env env, @@ -531,6 +575,7 @@ This API returns a JavaScript `Error` with the text provided. #### napi_create_type_error ```C NAPI_EXTERN napi_status napi_create_type_error(napi_env env, @@ -552,6 +597,7 @@ This API returns a JavaScript `TypeError` with the text provided. #### napi_create_range_error ```C NAPI_EXTERN napi_status napi_create_range_error(napi_env env, @@ -573,6 +619,7 @@ This API returns a JavaScript `RangeError` with the text provided. #### napi_get_and_clear_last_exception ```C napi_status napi_get_and_clear_last_exception(napi_env env, @@ -591,6 +638,7 @@ This API can be called even if there is a pending JavaScript exception. #### napi_is_exception_pending ```C napi_status napi_is_exception_pending(napi_env env, bool* result); @@ -608,7 +656,9 @@ This API can be called even if there is a pending JavaScript exception. #### napi_fatal_exception + ```C napi_status napi_fatal_exception(napi_env env, napi_value err); ``` @@ -627,6 +677,7 @@ thrown to immediately terminate the process. #### napi_fatal_error ```C NAPI_NO_RETURN void napi_fatal_error(const char* location, @@ -740,6 +791,7 @@ can only be called once. #### napi_open_handle_scope ```C NAPI_EXTERN napi_status napi_open_handle_scope(napi_env env, @@ -755,6 +807,7 @@ This API open a new scope. #### napi_close_handle_scope ```C NAPI_EXTERN napi_status napi_close_handle_scope(napi_env env, @@ -773,6 +826,7 @@ This API can be called even if there is a pending JavaScript exception. #### napi_open_escapable_handle_scope ```C NAPI_EXTERN napi_status @@ -790,6 +844,7 @@ to the outer scope. #### napi_close_escapable_handle_scope ```C NAPI_EXTERN napi_status @@ -809,6 +864,7 @@ This API can be called even if there is a pending JavaScript exception. #### napi_escape_handle ```C napi_status napi_escape_handle(napi_env env, @@ -874,6 +930,7 @@ individual count. #### napi_create_reference ```C NAPI_EXTERN napi_status napi_create_reference(napi_env env, @@ -896,6 +953,7 @@ to the `Object` passed in. #### napi_delete_reference ```C NAPI_EXTERN napi_status napi_delete_reference(napi_env env, napi_ref ref); @@ -913,6 +971,7 @@ This API can be called even if there is a pending JavaScript exception. #### napi_reference_ref ```C NAPI_EXTERN napi_status napi_reference_ref(napi_env env, @@ -931,6 +990,7 @@ passed in and returns the resulting reference count. #### napi_reference_unref ```C NAPI_EXTERN napi_status napi_reference_unref(napi_env env, @@ -949,6 +1009,7 @@ passed in and returns the resulting reference count. #### napi_get_reference_value ```C NAPI_EXTERN napi_status napi_get_reference_value(napi_env env, @@ -982,7 +1043,9 @@ should be freed up. #### napi_add_env_cleanup_hook + ```C NODE_EXTERN napi_status napi_add_env_cleanup_hook(napi_env env, void (*fun)(void* arg), @@ -1007,7 +1070,9 @@ is being torn down anyway. #### napi_remove_env_cleanup_hook + ```C NAPI_EXTERN napi_status napi_remove_env_cleanup_hook(napi_env env, void (*fun)(void* arg), @@ -1196,6 +1261,7 @@ Elements of this enum correspond to #### napi_create_array ```C napi_status napi_create_array(napi_env env, napi_value* result) @@ -1213,6 +1279,7 @@ JavaScript arrays are described in #### napi_create_array_with_length ```C napi_status napi_create_array_with_length(napi_env env, @@ -1241,6 +1308,7 @@ JavaScript arrays are described in #### napi_create_arraybuffer ```C napi_status napi_create_arraybuffer(napi_env env, @@ -1272,6 +1340,7 @@ JavaScript `ArrayBuffer` objects are described in #### napi_create_buffer ```C napi_status napi_create_buffer(napi_env env, @@ -1293,6 +1362,7 @@ fully-supported data structure, in most cases using a `TypedArray` will suffice. #### napi_create_buffer_copy ```C napi_status napi_create_buffer_copy(napi_env env, @@ -1318,6 +1388,7 @@ structure, in most cases using a `TypedArray` will suffice. #### napi_create_external ```C napi_status napi_create_external(napi_env env, @@ -1350,6 +1421,7 @@ an external value yields `napi_external`. #### napi_create_external_arraybuffer ```C napi_status @@ -1384,6 +1456,7 @@ JavaScript `ArrayBuffer`s are described in #### napi_create_external_buffer ```C napi_status napi_create_external_buffer(napi_env env, @@ -1415,6 +1488,7 @@ For Node.js >=4 `Buffers` are `Uint8Array`s. #### napi_create_function ```C napi_status napi_create_function(napi_env env, @@ -1448,6 +1522,7 @@ of the ECMAScript Language Specification. #### napi_create_object ```C napi_status napi_create_object(napi_env env, napi_value* result) @@ -1468,6 +1543,7 @@ ECMAScript Language Specification. #### napi_create_symbol ```C napi_status napi_create_symbol(napi_env env, @@ -1491,6 +1567,7 @@ of the ECMAScript Language Specification. #### napi_create_typedarray ```C napi_status napi_create_typedarray(napi_env env, @@ -1526,6 +1603,7 @@ JavaScript `TypedArray` objects are described in #### napi_create_dataview ```C @@ -1560,6 +1638,7 @@ JavaScript `DataView` objects are described in #### napi_create_int32 ```C napi_status napi_create_int32(napi_env env, int32_t value, napi_value* result) @@ -1580,6 +1659,7 @@ The JavaScript `Number` type is described in #### napi_create_uint32 ```C napi_status napi_create_uint32(napi_env env, uint32_t value, napi_value* result) @@ -1600,6 +1680,7 @@ The JavaScript `Number` type is described in #### napi_create_int64 ```C napi_status napi_create_int64(napi_env env, int64_t value, napi_value* result) @@ -1626,6 +1707,7 @@ outside the range of #### napi_create_double ```C napi_status napi_create_double(napi_env env, double value, napi_value* result) @@ -1646,6 +1728,7 @@ The JavaScript `Number` type is described in #### napi_create_string_latin1 ```C napi_status napi_create_string_latin1(napi_env env, @@ -1671,6 +1754,7 @@ The JavaScript `String` type is described in #### napi_create_string_utf16 ```C napi_status napi_create_string_utf16(napi_env env, @@ -1696,6 +1780,7 @@ The JavaScript `String` type is described in #### napi_create_string_utf8 ```C napi_status napi_create_string_utf8(napi_env env, @@ -1722,6 +1807,7 @@ The JavaScript `String` type is described in #### napi_get_array_length ```C napi_status napi_get_array_length(napi_env env, @@ -1745,6 +1831,7 @@ of the ECMAScript Language Specification. #### napi_get_arraybuffer_info ```C napi_status napi_get_arraybuffer_info(napi_env env, @@ -1774,6 +1861,7 @@ trigger a GC. #### napi_get_buffer_info ```C napi_status napi_get_buffer_info(napi_env env, @@ -1798,6 +1886,7 @@ lifetime is not guaranteed if it's managed by the VM. #### napi_get_prototype ```C napi_status napi_get_prototype(napi_env env, @@ -1816,6 +1905,7 @@ Returns `napi_ok` if the API succeeded. #### napi_get_typedarray_info ```C napi_status napi_get_typedarray_info(napi_env env, @@ -1852,6 +1942,7 @@ is managed by the VM. #### napi_get_dataview_info ```C @@ -1879,6 +1970,7 @@ This API returns various properties of a `DataView`. #### napi_get_value_bool ```C napi_status napi_get_value_bool(napi_env env, napi_value value, bool* result) @@ -1898,6 +1990,7 @@ This API returns the C boolean primitive equivalent of the given JavaScript #### napi_get_value_double ```C napi_status napi_get_value_double(napi_env env, @@ -1919,6 +2012,7 @@ This API returns the C double primitive equivalent of the given JavaScript #### napi_get_value_external ```C napi_status napi_get_value_external(napi_env env, @@ -1939,6 +2033,7 @@ This API retrieves the external data pointer that was previously passed to #### napi_get_value_int32 ```C napi_status napi_get_value_int32(napi_env env, @@ -1967,6 +2062,7 @@ result to zero. #### napi_get_value_int64 ```C napi_status napi_get_value_int64(napi_env env, @@ -1997,6 +2093,7 @@ result to zero. #### napi_get_value_string_latin1 ```C napi_status napi_get_value_string_latin1(napi_env env, @@ -2024,6 +2121,7 @@ in. #### napi_get_value_string_utf8 ```C napi_status napi_get_value_string_utf8(napi_env env, @@ -2050,6 +2148,7 @@ This API returns the UTF8-encoded string corresponding the value passed in. #### napi_get_value_string_utf16 ```C napi_status napi_get_value_string_utf16(napi_env env, @@ -2076,6 +2175,7 @@ This API returns the UTF16-encoded string corresponding the value passed in. #### napi_get_value_uint32 ```C napi_status napi_get_value_uint32(napi_env env, @@ -2098,6 +2198,7 @@ This API returns the C primitive equivalent of the given `napi_value` as a #### napi_get_boolean ```C napi_status napi_get_boolean(napi_env env, bool value, napi_value* result) @@ -2116,6 +2217,7 @@ represent the given boolean value. #### napi_get_global ```C napi_status napi_get_global(napi_env env, napi_value* result) @@ -2131,6 +2233,7 @@ This API returns the `global` object. #### napi_get_null ```C napi_status napi_get_null(napi_env env, napi_value* result) @@ -2146,6 +2249,7 @@ This API returns the `null` object. #### napi_get_undefined ```C napi_status napi_get_undefined(napi_env env, napi_value* result) @@ -2174,6 +2278,7 @@ These APIs support doing one of the following: ### napi_coerce_to_bool ```C napi_status napi_coerce_to_bool(napi_env env, @@ -2195,6 +2300,7 @@ This API can be re-entrant if getters are defined on the passed-in `Object`. ### napi_coerce_to_number ```C napi_status napi_coerce_to_number(napi_env env, @@ -2216,6 +2322,7 @@ This API can be re-entrant if getters are defined on the passed-in `Object`. ### napi_coerce_to_object ```C napi_status napi_coerce_to_object(napi_env env, @@ -2237,6 +2344,7 @@ This API can be re-entrant if getters are defined on the passed-in `Object`. ### napi_coerce_to_string ```C napi_status napi_coerce_to_string(napi_env env, @@ -2258,6 +2366,7 @@ This API can be re-entrant if getters are defined on the passed-in `Object`. ### napi_typeof ```C napi_status napi_typeof(napi_env env, napi_value value, napi_valuetype* result) @@ -2279,6 +2388,7 @@ If `value` has a type that is invalid, an error is returned. ### napi_instanceof ```C napi_status napi_instanceof(napi_env env, @@ -2304,6 +2414,7 @@ of the ECMAScript Language Specification. ### napi_is_array ```C napi_status napi_is_array(napi_env env, napi_value value, bool* result) @@ -2322,6 +2433,7 @@ of the ECMAScript Language Specification. ### napi_is_arraybuffer ```C napi_status napi_is_arraybuffer(napi_env env, napi_value value, bool* result) @@ -2338,6 +2450,7 @@ This API checks if the `Object` passed in is an array buffer. ### napi_is_buffer ```C napi_status napi_is_buffer(napi_env env, napi_value value, bool* result) @@ -2355,6 +2468,7 @@ This API checks if the `Object` passed in is a buffer. ### napi_is_error ```C napi_status napi_is_error(napi_env env, napi_value value, bool* result) @@ -2371,6 +2485,7 @@ This API checks if the `Object` passed in is an `Error`. ### napi_is_typedarray ```C napi_status napi_is_typedarray(napi_env env, napi_value value, bool* result) @@ -2387,6 +2502,7 @@ This API checks if the `Object` passed in is a typed array. ### napi_is_dataview ```C @@ -2404,6 +2520,7 @@ This API checks if the `Object` passed in is a `DataView`. ### napi_strict_equals ```C napi_status napi_strict_equals(napi_env env, @@ -2636,6 +2753,7 @@ this function is invoked. #### napi_get_property_names ```C napi_status napi_get_property_names(napi_env env, @@ -2659,6 +2777,7 @@ included. #### napi_set_property ```C napi_status napi_set_property(napi_env env, @@ -2679,6 +2798,7 @@ This API set a property on the `Object` passed in. #### napi_get_property ```C napi_status napi_get_property(napi_env env, @@ -2699,6 +2819,7 @@ This API gets the requested property from the `Object` passed in. #### napi_has_property ```C napi_status napi_has_property(napi_env env, @@ -2719,6 +2840,7 @@ This API checks if the `Object` passed in has the named property. #### napi_delete_property ```C napi_status napi_delete_property(napi_env env, @@ -2740,6 +2862,7 @@ This API attempts to delete the `key` own property from `object`. #### napi_has_own_property ```C napi_status napi_has_own_property(napi_env env, @@ -2762,6 +2885,7 @@ any conversion between data types. #### napi_set_named_property ```C napi_status napi_set_named_property(napi_env env, @@ -2783,6 +2907,7 @@ created from the string passed in as `utf8Name`. #### napi_get_named_property ```C napi_status napi_get_named_property(napi_env env, @@ -2804,6 +2929,7 @@ created from the string passed in as `utf8Name`. #### napi_has_named_property ```C napi_status napi_has_named_property(napi_env env, @@ -2825,6 +2951,7 @@ created from the string passed in as `utf8Name`. #### napi_set_element ```C napi_status napi_set_element(napi_env env, @@ -2845,6 +2972,7 @@ This API sets and element on the `Object` passed in. #### napi_get_element ```C napi_status napi_get_element(napi_env env, @@ -2865,6 +2993,7 @@ This API gets the element at the requested index. #### napi_has_element ```C napi_status napi_has_element(napi_env env, @@ -2886,6 +3015,7 @@ requested index. #### napi_delete_element ```C napi_status napi_delete_element(napi_env env, @@ -2907,6 +3037,7 @@ This API attempts to delete the specified `index` from `object`. #### napi_define_properties ```C napi_status napi_define_properties(napi_env env, @@ -2950,6 +3081,7 @@ function. ### napi_call_function ```C napi_status napi_call_function(napi_env env, @@ -3016,6 +3148,7 @@ if (status != napi_ok) return; ### napi_create_function ```C napi_status napi_create_function(napi_env env, @@ -3083,6 +3216,7 @@ responsible for creating the `.node` file. ### napi_get_cb_info ```C napi_status napi_get_cb_info(napi_env env, @@ -3113,6 +3247,7 @@ call like the arguments and the `this` pointer from a given callback info. ### napi_get_new_target ```C napi_status napi_get_new_target(napi_env env, @@ -3132,6 +3267,7 @@ callback is not a constructor call, the result is `NULL`. ### napi_new_instance ```C napi_status napi_new_instance(napi_env env, @@ -3227,6 +3363,7 @@ The reference must be freed once it is no longer needed. ### napi_define_class ```C napi_status napi_define_class(napi_env env, @@ -3283,6 +3420,7 @@ reference count is kept >= 1. ### napi_wrap ```C napi_status napi_wrap(napi_env env, @@ -3343,6 +3481,7 @@ first. ### napi_unwrap ```C napi_status napi_unwrap(napi_env env, @@ -3368,6 +3507,7 @@ then by calling `napi_unwrap()` on the wrapper object. ### napi_remove_wrap ```C napi_status napi_remove_wrap(napi_env env, @@ -3444,6 +3584,7 @@ callback invocation, even when it was cancelled. ### napi_create_async_work ```C napi_status napi_delete_async_work(napi_env env, @@ -3509,6 +3651,7 @@ This API can be called even if there is a pending JavaScript exception. ### napi_queue_async_work ```C napi_status napi_queue_async_work(napi_env env, @@ -3526,6 +3669,7 @@ for execution. ### napi_cancel_async_work ```C napi_status napi_cancel_async_work(napi_env env, @@ -3555,6 +3699,7 @@ the runtime. ### napi_async_init ```C napi_status napi_async_init(napi_env env, @@ -3576,6 +3721,7 @@ Returns `napi_ok` if the API succeeded. ### napi_async_destroy ```C napi_status napi_async_destroy(napi_env env, @@ -3592,6 +3738,7 @@ This API can be called even if there is a pending JavaScript exception. ### napi_make_callback ```C NAPI_EXTERN napi_status napi_open_callback_scope(napi_env env, @@ -3663,6 +3811,7 @@ the required scope. ### napi_close_callback_scope ```C NAPI_EXTERN napi_status napi_close_callback_scope(napi_env env, @@ -3678,6 +3827,7 @@ This API can be called even if there is a pending JavaScript exception. ### napi_get_node_version ```C @@ -3706,6 +3856,7 @@ The returned buffer is statically allocated and does not need to be freed. ### napi_get_version ```C napi_status napi_get_version(napi_env env, @@ -3736,6 +3887,7 @@ support it: ### napi_adjust_external_memory ```C NAPI_EXTERN napi_status napi_adjust_external_memory(napi_env env, @@ -3815,6 +3967,7 @@ deferred = NULL; ### napi_create_promise ```C napi_status napi_create_promise(napi_env env, @@ -3835,6 +3988,7 @@ This API creates a deferred object and a JavaScript promise. ### napi_resolve_deferred ```C napi_status napi_resolve_deferred(napi_env env, @@ -3858,6 +4012,7 @@ The deferred object is freed upon successful completion. ### napi_reject_deferred ```C napi_status napi_reject_deferred(napi_env env, @@ -3881,6 +4036,7 @@ The deferred object is freed upon successful completion. ### napi_is_promise ```C napi_status napi_is_promise(napi_env env, @@ -3901,6 +4057,7 @@ underlying JavaScript engine. ### napi_run_script ```C NAPI_EXTERN napi_status napi_run_script(napi_env env, @@ -3919,7 +4076,10 @@ a specific `napi_env`. ### napi_get_uv_event_loop ```C NAPI_EXTERN napi_status napi_get_uv_event_loop(napi_env env, diff --git a/src/node_api.h b/src/node_api.h index 84706ac3ed6769..b22592db15f110 100644 --- a/src/node_api.h +++ b/src/node_api.h @@ -7,6 +7,16 @@ struct uv_loop_s; // Forward declaration. +#ifndef NAPI_VERSION +#ifdef NAPI_EXPERIMENTAL +// Use INT_MAX, this should only be consumed by the pre-processor anyway. +#define NAPI_VERSION 2147483647 +#else +// The baseline version for N-API +#define NAPI_VERSION 3 +#endif +#endif + #ifdef _WIN32 #ifdef BUILDING_NODE_EXTENSION #ifdef EXTERNAL_NAPI @@ -118,19 +128,10 @@ EXTERN_C_START NAPI_EXTERN void napi_module_register(napi_module* mod); -NAPI_EXTERN napi_status napi_add_env_cleanup_hook(napi_env env, - void (*fun)(void* arg), - void* arg); -NAPI_EXTERN napi_status napi_remove_env_cleanup_hook(napi_env env, - void (*fun)(void* arg), - void* arg); - NAPI_EXTERN napi_status napi_get_last_error_info(napi_env env, const napi_extended_error_info** result); -NAPI_EXTERN napi_status napi_fatal_exception(napi_env env, napi_value err); - NAPI_EXTERN NAPI_NO_RETURN void napi_fatal_error(const char* location, size_t location_len, const char* message, @@ -443,14 +444,6 @@ NAPI_EXTERN napi_status napi_escape_handle(napi_env env, napi_value escapee, napi_value* result); -NAPI_EXTERN napi_status napi_open_callback_scope(napi_env env, - napi_value resource_object, - napi_async_context context, - napi_callback_scope* result); - -NAPI_EXTERN napi_status napi_close_callback_scope(napi_env env, - napi_callback_scope scope); - // Methods to support error handling NAPI_EXTERN napi_status napi_throw(napi_env env, napi_value error); NAPI_EXTERN napi_status napi_throw_error(napi_env env, @@ -610,11 +603,38 @@ NAPI_EXTERN napi_status napi_run_script(napi_env env, napi_value script, napi_value* result); +#if NAPI_VERSION >= 2 + // Return the current libuv event loop for a given environment NAPI_EXTERN napi_status napi_get_uv_event_loop(napi_env env, struct uv_loop_s** loop); +#endif // NAPI_VERSION >= 2 + +#if NAPI_VERSION >= 3 + +NAPI_EXTERN napi_status napi_open_callback_scope(napi_env env, + napi_value resource_object, + napi_async_context context, + napi_callback_scope* result); + +NAPI_EXTERN napi_status napi_close_callback_scope(napi_env env, + napi_callback_scope scope); + +NAPI_EXTERN napi_status napi_fatal_exception(napi_env env, napi_value err); + +NAPI_EXTERN napi_status napi_add_env_cleanup_hook(napi_env env, + void (*fun)(void* arg), + void* arg); + +NAPI_EXTERN napi_status napi_remove_env_cleanup_hook(napi_env env, + void (*fun)(void* arg), + void* arg); + +#endif // NAPI_VERSION >= 3 + #ifdef NAPI_EXPERIMENTAL + // Calling into JS from other threads NAPI_EXTERN napi_status napi_create_threadsafe_function(napi_env env, @@ -652,6 +672,7 @@ NAPI_EXTERN napi_status napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func); #endif // NAPI_EXPERIMENTAL + EXTERN_C_END #endif // SRC_NODE_API_H_ diff --git a/tools/doc/common.js b/tools/doc/common.js index 813935f23b84f4..4dfadd353d9ec8 100644 --- a/tools/doc/common.js +++ b/tools/doc/common.js @@ -25,6 +25,10 @@ function extractAndParseYAML(text) { meta.added = arrify(meta.added); } + if (meta.napiVersion) { + meta.napiVersion = arrify(meta.napiVersion); + } + if (meta.deprecated) { // Treat deprecated like added for consistency. meta.deprecated = arrify(meta.deprecated); diff --git a/tools/doc/html.js b/tools/doc/html.js index ae2da58b7a0131..871a55baf4676c 100644 --- a/tools/doc/html.js +++ b/tools/doc/html.js @@ -261,6 +261,10 @@ function parseYAML(text) { html += `${added.description}${deprecated.description}\n`; } + if (meta.napiVersion) { + html += `N-API version: ${meta.napiVersion.join(', ')}\n`; + } + html += ''; return html; }