Skip to content

Commit 2de000c

Browse files
node-api: add warning for NAPI_EXPERIMENTAL
1 parent 6710c00 commit 2de000c

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

src/js_native_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ node_api_post_finalizer(node_api_basic_env env,
536536
void* finalize_data,
537537
void* finalize_hint);
538538

539+
#warning "NAPI_EXPERIMENTAL is enabled. Experimental features may be unstable."
540+
539541
#endif // NAPI_EXPERIMENTAL
540542

541543
#if NAPI_VERSION >= 6

src/node_api.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,10 @@ node_api_get_module_file_name(node_api_basic_env env, const char** result);
266266

267267
EXTERN_C_END
268268

269+
#ifdef NAPI_EXPERIMENTAL
270+
271+
#warning "NAPI_EXPERIMENTAL is enabled. Experimental features may be unstable."
272+
273+
#endif // NAPI_EXPERIMENTAL
274+
269275
#endif // SRC_NODE_API_H_

test/addons/hello-world/binding.gyp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
'target_name': 'binding2',
1010
'sources': [ 'binding2.cc' ],
1111
'includes': ['../common.gypi'],
12+
},
13+
{
14+
'target_name': 'binding_experimental',
15+
'sources': [ 'binding_experimental.cc' ],
16+
'includes': ['../common.gypi'],
17+
'defines': [ 'NAPI_EXPERIMENTAL' ],
1218
}
1319
]
1420
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <node_api.h>
2+
3+
static napi_value Method(const napi_env env,
4+
const napi_callback_info info) {
5+
napi_value result;
6+
napi_create_string_utf8(env, "world", NAPI_AUTO_LENGTH, &result);
7+
return result;
8+
}
9+
10+
static napi_value InitModule(napi_env env, napi_value exports) {
11+
napi_value hello;
12+
napi_create_function(env, "hello", NAPI_AUTO_LENGTH, Method, nullptr, &hello);
13+
napi_set_named_property(env, exports, "hello", hello);
14+
return exports;
15+
}
16+
17+
NAPI_MODULE(NODE_GYP_MODULE_NAME, InitModule)

test/addons/hello-world/test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ delete require.cache[bindingPath];
1414
const rebinding = require(bindingPath);
1515
assert.strictEqual(rebinding.hello(), 'world');
1616
assert.notStrictEqual(binding.hello, rebinding.hello);
17+
18+
const binding_experimental = require(require.resolve(`./build/${common.buildType}/binding_experimental`));
19+
assert.strictEqual(binding_experimental.hello(), 'world');
20+
console.log('binding_experimental.hello() =', binding_experimental.hello());

0 commit comments

Comments
 (0)