Skip to content

Commit e7202ac

Browse files
node-api: define version 10
Notable runtime changes to existing APIs: - returning `node_api_cannot_run_js` instead of `napi_pending_exception`. - allow creating references to objects, functions, and symbols.
1 parent 9b6cea6 commit e7202ac

File tree

10 files changed

+19
-26
lines changed

10 files changed

+19
-26
lines changed

doc/contributing/releases-node-api.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ with:
8585
8686
```bash
8787
grep \
88-
-E \
88+
-nHE \
8989
'N(ODE_)?API_EXPERIMENTAL' \
9090
src/js_native_api{_types,}.h \
9191
src/node_api{_types,}.h
@@ -95,13 +95,13 @@ and update the define version guards with the release version:
9595

9696
```diff
9797
- #ifdef NAPI_EXPERIMENTAL
98-
+ #if NAPI_VERSION >= 10
98+
+ #if NAPI_VERSION >= 11
9999

100100
NAPI_EXTERN napi_status NAPI_CDECL
101101
node_api_function(napi_env env);
102102

103103
- #endif // NAPI_EXPERIMENTAL
104-
+ #endif // NAPI_VERSION >= 10
104+
+ #endif // NAPI_VERSION >= 11
105105
```
106106
107107
Remove any feature flags of the form `NODE_API_EXPERIMENTAL_HAS_<FEATURE>`.
@@ -121,11 +121,11 @@ Also, update the Node-API version value of the `napi_get_version` test in
121121
#### Step 2. Update runtime version guards
122122

123123
If this release includes runtime behavior version guards, the relevant commits
124-
should already include `NAPI_VERSION_EXPERIMENTAL` guard for the change. Check
125-
for these guards with:
124+
should already include the `NAPI_VERSION_EXPERIMENTAL` guard for the change.
125+
Check for these guards with:
126126

127127
```bash
128-
grep NAPI_VERSION_EXPERIMENTAL src/js_native_api_v8* src/node_api.cc
128+
grep -nH NAPI_VERSION_EXPERIMENTAL src/js_native_api_v8* src/node_api.cc
129129
```
130130

131131
and substitute this guard version with the release version `x`.
@@ -138,7 +138,7 @@ Check for these definitions with:
138138

139139
```bash
140140
grep \
141-
-E \
141+
-nHE \
142142
'N(ODE_)?API_EXPERIMENTAL' \
143143
test/node-api/*/{*.{h,c},binding.gyp} \
144144
test/js-native-api/*/{*.{h,c},binding.gyp}
@@ -186,7 +186,7 @@ For all runtime version guards updated in Step 2, check for these definitions
186186
with:
187187

188188
```bash
189-
grep NAPI_EXPERIMENTAL doc/api/n-api.md
189+
grep -nH NAPI_EXPERIMENTAL doc/api/n-api.md
190190
```
191191

192192
In `doc/api/n-api.md`, update the `experimental` change history item to be the

src/js_native_api.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_string_utf16(napi_env env,
9292
const char16_t* str,
9393
size_t length,
9494
napi_value* result);
95-
#ifdef NAPI_EXPERIMENTAL
96-
#define NODE_API_EXPERIMENTAL_HAS_EXTERNAL_STRINGS
95+
#if NAPI_VERSION >= 10
9796
NAPI_EXTERN napi_status NAPI_CDECL node_api_create_external_string_latin1(
9897
napi_env env,
9998
char* str,
@@ -110,17 +109,14 @@ node_api_create_external_string_utf16(napi_env env,
110109
void* finalize_hint,
111110
napi_value* result,
112111
bool* copied);
113-
#endif // NAPI_EXPERIMENTAL
114112

115-
#ifdef NAPI_EXPERIMENTAL
116-
#define NODE_API_EXPERIMENTAL_HAS_PROPERTY_KEYS
117113
NAPI_EXTERN napi_status NAPI_CDECL node_api_create_property_key_latin1(
118114
napi_env env, const char* str, size_t length, napi_value* result);
119115
NAPI_EXTERN napi_status NAPI_CDECL node_api_create_property_key_utf8(
120116
napi_env env, const char* str, size_t length, napi_value* result);
121117
NAPI_EXTERN napi_status NAPI_CDECL node_api_create_property_key_utf16(
122118
napi_env env, const char16_t* str, size_t length, napi_value* result);
123-
#endif // NAPI_EXPERIMENTAL
119+
#endif // NAPI_VERSION >= 10
124120

125121
NAPI_EXTERN napi_status NAPI_CDECL napi_create_symbol(napi_env env,
126122
napi_value description,

src/js_native_api_v8.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2753,7 +2753,7 @@ napi_status NAPI_CDECL napi_create_reference(napi_env env,
27532753
CHECK_ARG(env, result);
27542754

27552755
v8::Local<v8::Value> v8_value = v8impl::V8LocalValueFromJsValue(value);
2756-
if (env->module_api_version != NAPI_VERSION_EXPERIMENTAL) {
2756+
if (env->module_api_version < 10) {
27572757
if (!(v8_value->IsObject() || v8_value->IsFunction() ||
27582758
v8_value->IsSymbol())) {
27592759
return napi_set_last_error(env, napi_invalid_arg);

src/js_native_api_v8.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ inline napi_status napi_set_last_error(node_api_basic_env basic_env,
236236
(env), (env)->last_exception.IsEmpty(), napi_pending_exception); \
237237
RETURN_STATUS_IF_FALSE((env), \
238238
(env)->can_call_into_js(), \
239-
(env->module_api_version == NAPI_VERSION_EXPERIMENTAL \
239+
(env->module_api_version >= 10 \
240240
? napi_cannot_run_js \
241241
: napi_pending_exception)); \
242242
napi_clear_last_error((env)); \

src/node_api.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,11 +678,13 @@ node::addon_context_register_func get_node_api_context_register_func(
678678
const char* module_name,
679679
int32_t module_api_version) {
680680
static_assert(
681-
NODE_API_SUPPORTED_VERSION_MAX == 9,
681+
NODE_API_SUPPORTED_VERSION_MAX == 10,
682682
"New version of Node-API requires adding another else-if statement below "
683683
"for the new version and updating this assert condition.");
684684
if (module_api_version == 9) {
685685
return node_api_context_register_func<9>;
686+
} else if (module_api_version == 10) {
687+
return node_api_context_register_func<10>;
686688
} else if (module_api_version == NAPI_VERSION_EXPERIMENTAL) {
687689
return node_api_context_register_func<NAPI_VERSION_EXPERIMENTAL>;
688690
} else if (module_api_version >= NODE_API_SUPPORTED_VERSION_MIN &&

src/node_api.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,15 @@ napi_create_external_buffer(napi_env env,
136136
napi_value* result);
137137
#endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
138138

139-
#ifdef NAPI_EXPERIMENTAL
140-
#define NODE_API_EXPERIMENTAL_HAS_CREATE_BUFFER_FROM_ARRAYBUFFER
139+
#if NAPI_VERSION >= 10
141140

142141
NAPI_EXTERN napi_status NAPI_CDECL
143142
node_api_create_buffer_from_arraybuffer(napi_env env,
144143
napi_value arraybuffer,
145144
size_t byte_offset,
146145
size_t byte_length,
147146
napi_value* result);
148-
#endif // NAPI_EXPERIMENTAL
147+
#endif // NAPI_VERSION >= 10
149148

150149
NAPI_EXTERN napi_status NAPI_CDECL napi_create_buffer_copy(napi_env env,
151150
size_t length,

src/node_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100

101101
// The NAPI_VERSION supported by the runtime. This is the inclusive range of
102102
// versions which the Node.js binary being built supports.
103-
#define NODE_API_SUPPORTED_VERSION_MAX 9
103+
#define NODE_API_SUPPORTED_VERSION_MAX 10
104104
#define NODE_API_SUPPORTED_VERSION_MIN 1
105105

106106
// Node API modules use NAPI_VERSION 8 by default if it is not explicitly

test/js-native-api/test_finalizer/binding.gyp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"targets": [
33
{
44
"target_name": "test_finalizer",
5-
"defines": [ "NAPI_EXPERIMENTAL" ],
65
"sources": [
76
"test_finalizer.c"
87
]

test/js-native-api/test_general/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ assert.notStrictEqual(test_general.testGetPrototype(baseObject),
3434
test_general.testGetPrototype(extendedObject));
3535

3636
// Test version management functions
37-
assert.strictEqual(test_general.testGetVersion(), 9);
37+
assert.strictEqual(test_general.testGetVersion(), 10);
3838

3939
[
4040
123,

test/js-native-api/test_string/binding.gyp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
"test_string.c",
77
"test_null.c",
88
],
9-
"defines": [
10-
"NAPI_EXPERIMENTAL",
11-
],
129
},
1310
],
1411
}

0 commit comments

Comments
 (0)