Skip to content

Commit a8c0a43

Browse files
Gabriel Schulhofmhdawson
Gabriel Schulhof
authored andcommitted
n-api: remove n-api module loading flag
Remove the command line flag that was needed for N-API module loading. Re: nodejs/vm#9 PR-URL: #14902 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Hitesh Kanwathirtha <[email protected]>
1 parent faaefa8 commit a8c0a43

File tree

15 files changed

+86
-70
lines changed

15 files changed

+86
-70
lines changed

doc/api/cli.md

-9
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,6 @@ added: v8.4.0
178178

179179
Enable the experimental `'http2'` module.
180180

181-
### `--napi-modules`
182-
<!-- YAML
183-
added: v8.0.0
184-
-->
185-
186-
Enable loading native modules compiled with the ABI-stable Node.js API (N-API)
187-
(experimental).
188-
189181
### `--abort-on-uncaught-exception`
190182
<!-- YAML
191183
added: v0.10
@@ -453,7 +445,6 @@ Node options that are allowed are:
453445
- `--inspect-brk`
454446
- `--inspect-port`
455447
- `--inspect`
456-
- `--napi-modules`
457448
- `--no-deprecation`
458449
- `--no-warnings`
459450
- `--openssl-config`

doc/api/n-api.md

-8
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,6 @@ For example:
6363
#include <node_api.h>
6464
```
6565

66-
As the feature is experimental it must be enabled with the
67-
following command line
68-
[option](https://nodejs.org/dist/latest-v8.x/docs/api/cli.html#cli_napi_modules):
69-
70-
```bash
71-
--napi-modules
72-
```
73-
7466
## Basic N-API Data Types
7567

7668
N-API exposes the following fundamental datatypes as abstractions that are

src/env-inl.h

+1
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ inline Environment::Environment(IsolateData* isolate_data,
288288
printed_error_(false),
289289
trace_sync_io_(false),
290290
abort_on_uncaught_exception_(false),
291+
emit_napi_warning_(true),
291292
makecallback_cntr_(0),
292293
#if HAVE_INSPECTOR
293294
inspector_agent_(this),

src/env.cc

+6
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ bool Environment::RemovePromiseHook(promise_hook_func fn, void* arg) {
213213
return true;
214214
}
215215

216+
bool Environment::EmitNapiWarning() {
217+
bool current_value = emit_napi_warning_;
218+
emit_napi_warning_ = false;
219+
return current_value;
220+
}
221+
216222
void Environment::EnvPromiseHook(v8::PromiseHookType type,
217223
v8::Local<v8::Promise> promise,
218224
v8::Local<v8::Value> parent) {

src/env.h

+2
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ class Environment {
669669

670670
void AddPromiseHook(promise_hook_func fn, void* arg);
671671
bool RemovePromiseHook(promise_hook_func fn, void* arg);
672+
bool EmitNapiWarning();
672673

673674
private:
674675
inline void ThrowError(v8::Local<v8::Value> (*fun)(v8::Local<v8::String>),
@@ -690,6 +691,7 @@ class Environment {
690691
bool printed_error_;
691692
bool trace_sync_io_;
692693
bool abort_on_uncaught_exception_;
694+
bool emit_napi_warning_;
693695
size_t makecallback_cntr_;
694696
std::vector<double> destroy_ids_list_;
695697

src/node.cc

+18-30
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,6 @@ unsigned int reverted = 0;
197197
std::string icu_data_dir; // NOLINT(runtime/string)
198198
#endif
199199

200-
// N-API is in experimental state, disabled by default.
201-
bool load_napi_modules = false;
202-
203200
// used by C++ modules as well
204201
bool no_deprecation = false;
205202

@@ -2703,27 +2700,22 @@ static void DLOpen(const FunctionCallbackInfo<Value>& args) {
27032700
env->ThrowError("Module did not self-register.");
27042701
return;
27052702
}
2706-
if (mp->nm_version != NODE_MODULE_VERSION) {
2707-
char errmsg[1024];
2708-
if (mp->nm_version == -1) {
2709-
snprintf(errmsg,
2710-
sizeof(errmsg),
2711-
"The module '%s'"
2712-
"\nwas compiled against the ABI-stable Node.js API (N-API)."
2713-
"\nThis feature is experimental and must be enabled on the "
2714-
"\ncommand-line by adding --napi-modules.",
2715-
*filename);
2716-
} else {
2717-
snprintf(errmsg,
2718-
sizeof(errmsg),
2719-
"The module '%s'"
2720-
"\nwas compiled against a different Node.js version using"
2721-
"\nNODE_MODULE_VERSION %d. This version of Node.js requires"
2722-
"\nNODE_MODULE_VERSION %d. Please try re-compiling or "
2723-
"re-installing\nthe module (for instance, using `npm rebuild` "
2724-
"or `npm install`).",
2725-
*filename, mp->nm_version, NODE_MODULE_VERSION);
2703+
if (mp->nm_version == -1) {
2704+
if (env->EmitNapiWarning()) {
2705+
ProcessEmitWarning(env, "N-API is an experimental feature and could "
2706+
"change at any time.");
27262707
}
2708+
} else if (mp->nm_version != NODE_MODULE_VERSION) {
2709+
char errmsg[1024];
2710+
snprintf(errmsg,
2711+
sizeof(errmsg),
2712+
"The module '%s'"
2713+
"\nwas compiled against a different Node.js version using"
2714+
"\nNODE_MODULE_VERSION %d. This version of Node.js requires"
2715+
"\nNODE_MODULE_VERSION %d. Please try re-compiling or "
2716+
"re-installing\nthe module (for instance, using `npm rebuild` "
2717+
"or `npm install`).",
2718+
*filename, mp->nm_version, NODE_MODULE_VERSION);
27272719

27282720
// NOTE: `mp` is allocated inside of the shared library's memory, calling
27292721
// `dlclose` will deallocate it
@@ -3822,7 +3814,8 @@ static void PrintHelp() {
38223814
" --throw-deprecation throw an exception on deprecations\n"
38233815
" --pending-deprecation emit pending deprecation warnings\n"
38243816
" --no-warnings silence all process warnings\n"
3825-
" --napi-modules load N-API modules\n"
3817+
" --napi-modules load N-API modules (no-op - option\n"
3818+
" kept for compatibility)\n"
38263819
" --abort-on-uncaught-exception\n"
38273820
" aborting instead of exiting causes a\n"
38283821
" core file to be generated for analysis\n"
@@ -4080,7 +4073,7 @@ static void ParseArgs(int* argc,
40804073
} else if (strcmp(arg, "--no-deprecation") == 0) {
40814074
no_deprecation = true;
40824075
} else if (strcmp(arg, "--napi-modules") == 0) {
4083-
load_napi_modules = true;
4076+
// no-op
40844077
} else if (strcmp(arg, "--no-warnings") == 0) {
40854078
no_process_warnings = true;
40864079
} else if (strcmp(arg, "--trace-warnings") == 0) {
@@ -4735,11 +4728,6 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data,
47354728

47364729
env.set_trace_sync_io(trace_sync_io);
47374730

4738-
if (load_napi_modules) {
4739-
ProcessEmitWarning(&env, "N-API is an experimental feature "
4740-
"and could change at any time.");
4741-
}
4742-
47434731
{
47444732
SealHandleScope seal(isolate);
47454733
bool more;

src/node_api.cc

+1-19
Original file line numberDiff line numberDiff line change
@@ -841,28 +841,10 @@ void napi_module_register_cb(v8::Local<v8::Object> exports,
841841

842842
} // end of anonymous namespace
843843

844-
#ifndef EXTERNAL_NAPI
845-
namespace node {
846-
// Indicates whether NAPI was enabled/disabled via the node command-line.
847-
extern bool load_napi_modules;
848-
}
849-
#endif // EXTERNAL_NAPI
850-
851844
// Registers a NAPI module.
852845
void napi_module_register(napi_module* mod) {
853-
// NAPI modules always work with the current node version.
854-
int module_version = NODE_MODULE_VERSION;
855-
856-
#ifndef EXTERNAL_NAPI
857-
if (!node::load_napi_modules) {
858-
// NAPI is disabled, so set the module version to -1 to cause the module
859-
// to be unloaded.
860-
module_version = -1;
861-
}
862-
#endif // EXTERNAL_NAPI
863-
864846
node::node_module* nm = new node::node_module {
865-
module_version,
847+
-1,
866848
mod->nm_flags,
867849
nullptr,
868850
mod->nm_filename,

test/addons-napi/test_async/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if (process.argv[2] === 'child') {
1515
return;
1616
}
1717
const p = child_process.spawnSync(
18-
process.execPath, [ '--napi-modules', __filename, 'child' ]);
18+
process.execPath, [ __filename, 'child' ]);
1919
assert.ifError(p.error);
2020
assert.ok(p.stderr.toString().includes(testException));
2121

test/addons-napi/test_fatal/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (process.argv[2] === 'child') {
1212
}
1313

1414
const p = child_process.spawnSync(
15-
process.execPath, [ '--napi-modules', __filename, 'child' ]);
15+
process.execPath, [ __filename, 'child' ]);
1616
assert.ifError(p.error);
1717
assert.ok(p.stderr.toString().includes(
1818
'FATAL ERROR: test_fatal::Test fatal message'));

test/addons-napi/test_function/test_function.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ napi_value TestCallFunction(napi_env env, napi_callback_info info) {
2626
return result;
2727
}
2828

29-
void TestFunctionName(napi_env env, napi_callback_info info) {}
29+
napi_value TestFunctionName(napi_env env, napi_callback_info info) {
30+
return NULL;
31+
}
3032

3133
napi_value Init(napi_env env, napi_value exports) {
3234
napi_value fn1;
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"targets": [
3+
{
4+
"target_name": "test_warning",
5+
"sources": [ "test_warning.c" ]
6+
},
7+
{
8+
"target_name": "test_warning2",
9+
"sources": [ "test_warning2.c" ]
10+
}
11+
]
12+
}

test/addons-napi/test_warning/test.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
if (process.argv[2] === 'child') {
4+
const common = require('../../common');
5+
console.log(require(`./build/${common.buildType}/test_warning`));
6+
console.log(require(`./build/${common.buildType}/test_warning2`));
7+
} else {
8+
const run = require('child_process').spawnSync;
9+
const assert = require('assert');
10+
const warning = 'Warning: N-API is an experimental feature and could ' +
11+
'change at any time.';
12+
13+
const result = run(process.execPath, [__filename, 'child']);
14+
assert.deepStrictEqual(result.stdout.toString().match(/\S+/g), ['42', '1337'],
15+
'Modules loaded correctly');
16+
assert.deepStrictEqual(result.stderr.toString().split(warning).length, 2,
17+
'Warning was displayed only once');
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <node_api.h>
2+
#include "../common.h"
3+
4+
napi_value Init(napi_env env, napi_value exports) {
5+
napi_value result;
6+
NAPI_CALL(env,
7+
napi_create_uint32(env, 42, &result));
8+
return result;
9+
}
10+
11+
NAPI_MODULE(test_warning, Init)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <node_api.h>
2+
#include "../common.h"
3+
4+
napi_value Init(napi_env env, napi_value exports) {
5+
napi_value result;
6+
NAPI_CALL(env,
7+
napi_create_uint32(env, 1337, &result));
8+
return result;
9+
}
10+
11+
NAPI_MODULE(test_warning2, Init)

test/addons-napi/testcfg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
import testpy
44

55
def GetConfiguration(context, root):
6-
return testpy.AddonTestConfiguration(context, root, 'addons-napi', ['--napi-modules'])
6+
return testpy.AddonTestConfiguration(context, root, 'addons-napi')

0 commit comments

Comments
 (0)