Skip to content

Commit 5e29823

Browse files
Gabriel SchulhofMylesBorins
Gabriel Schulhof
authored andcommittedApr 16, 2018
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 Backport-PR-URL: #19447 PR-URL: #14902 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
1 parent f31b50c commit 5e29823

File tree

15 files changed

+83
-66
lines changed

15 files changed

+83
-66
lines changed
 

‎doc/api/cli.md

-9
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,6 @@ added: v6.0.0
119119

120120
Silence all process warnings (including deprecations).
121121

122-
### `--napi-modules`
123-
<!-- YAML
124-
added: REPLACEME
125-
-->
126-
127-
Enable loading native modules compiled with the ABI-stable Node.js API (N-API)
128-
(experimental).
129-
130122
### `--trace-warnings`
131123
<!-- YAML
132124
added: v6.0.0
@@ -361,7 +353,6 @@ Node options that are allowed are:
361353
- `--debug-brk`
362354
- `--debug-port`
363355
- `--debug`
364-
- `--napi-modules`
365356
- `--no-deprecation`
366357
- `--no-warnings`
367358
- `--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
@@ -223,6 +223,7 @@ inline Environment::Environment(v8::Local<v8::Context> context,
223223
using_domains_(false),
224224
printed_error_(false),
225225
trace_sync_io_(false),
226+
emit_napi_warning_(true),
226227
makecallback_cntr_(0),
227228
async_wrap_uid_(0),
228229
debugger_agent_(this),

‎src/env.cc

+6
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,10 @@ void Environment::PrintSyncTrace() const {
6161
fflush(stderr);
6262
}
6363

64+
bool Environment::EmitNapiWarning() {
65+
bool current_value = emit_napi_warning_;
66+
emit_napi_warning_ = false;
67+
return current_value;
68+
}
69+
6470
} // namespace node

‎src/env.h

+3
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,8 @@ class Environment {
535535

536536
static const int kContextEmbedderDataIndex = NODE_CONTEXT_EMBEDDER_DATA_INDEX;
537537

538+
bool EmitNapiWarning();
539+
538540
private:
539541
inline void ThrowError(v8::Local<v8::Value> (*fun)(v8::Local<v8::String>),
540542
const char* errmsg);
@@ -566,6 +568,7 @@ class Environment {
566568
bool using_domains_;
567569
bool printed_error_;
568570
bool trace_sync_io_;
571+
bool emit_napi_warning_;
569572
size_t makecallback_cntr_;
570573
int64_t async_wrap_uid_;
571574
std::vector<int64_t> destroy_ids_list_;

‎src/node.cc

+13-25
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ static node_module* modlist_addon;
167167
static std::string icu_data_dir; // NOLINT(runtime/string)
168168
#endif
169169

170-
// N-API is in experimental state, disabled by default.
171-
bool load_napi_modules = false;
172-
173170
// used by C++ modules as well
174171
bool no_deprecation = false;
175172

@@ -2503,22 +2500,17 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
25032500
env->ThrowError("Module did not self-register.");
25042501
return;
25052502
}
2506-
if (mp->nm_version != NODE_MODULE_VERSION) {
2507-
char errmsg[1024];
2508-
if (mp->nm_version == -1) {
2509-
snprintf(errmsg,
2510-
sizeof(errmsg),
2511-
"The module '%s'"
2512-
"\nwas compiled against the ABI-stable Node.js API (N-API)."
2513-
"\nThis feature is experimental and must be enabled on the "
2514-
"\ncommand-line by adding --napi-modules.",
2515-
*filename);
2516-
} else {
2517-
snprintf(errmsg,
2518-
sizeof(errmsg),
2519-
"Module version mismatch. Expected %d, got %d.",
2520-
NODE_MODULE_VERSION, mp->nm_version);
2503+
if (mp->nm_version == -1) {
2504+
if (env->EmitNapiWarning()) {
2505+
ProcessEmitWarning(env, "N-API is an experimental feature and could "
2506+
"change at any time.");
25212507
}
2508+
} else if (mp->nm_version != NODE_MODULE_VERSION) {
2509+
char errmsg[1024];
2510+
snprintf(errmsg,
2511+
sizeof(errmsg),
2512+
"Module version mismatch. Expected %d, got %d.",
2513+
NODE_MODULE_VERSION, mp->nm_version);
25222514

25232515
// NOTE: `mp` is allocated inside of the shared library's memory, calling
25242516
// `uv_dlclose` will deallocate it
@@ -3733,7 +3725,8 @@ static void PrintHelp() {
37333725
" --throw-deprecation throw an exception anytime a deprecated "
37343726
"function is used\n"
37353727
" --no-warnings silence all process warnings\n"
3736-
" --napi-modules load N-API modules\n"
3728+
" --napi-modules load N-API modules (no-op - option kept for "
3729+
" compatibility)\n"
37373730
" --trace-warnings show stack traces on process warnings\n"
37383731
" --redirect-warnings=path\n"
37393732
" write warnings to path instead of stderr\n"
@@ -3980,7 +3973,7 @@ static void ParseArgs(int* argc,
39803973
} else if (strcmp(arg, "--no-deprecation") == 0) {
39813974
no_deprecation = true;
39823975
} else if (strcmp(arg, "--napi-modules") == 0) {
3983-
load_napi_modules = true;
3976+
// no-op
39843977
} else if (strcmp(arg, "--no-warnings") == 0) {
39853978
no_process_warnings = true;
39863979
} else if (strcmp(arg, "--trace-warnings") == 0) {
@@ -4879,11 +4872,6 @@ static void StartNodeInstance(void* arg) {
48794872
if (instance_data->use_debug_agent())
48804873
EnableDebug(env);
48814874

4882-
if (load_napi_modules) {
4883-
ProcessEmitWarning(env, "N-API is an experimental feature "
4884-
"and could change at any time.");
4885-
}
4886-
48874875
{
48884876
SealHandleScope seal(isolate);
48894877
bool more;

‎src/node_api.cc

+1-19
Original file line numberDiff line numberDiff line change
@@ -846,28 +846,10 @@ void napi_module_register_cb(v8::Local<v8::Object> exports,
846846
}
847847
}
848848

849-
#ifndef EXTERNAL_NAPI
850-
namespace node {
851-
// Indicates whether NAPI was enabled/disabled via the node command-line.
852-
extern bool load_napi_modules;
853-
}
854-
#endif // EXTERNAL_NAPI
855-
856849
// Registers a NAPI module.
857850
void napi_module_register(napi_module* mod) {
858-
// NAPI modules always work with the current node version.
859-
int module_version = NODE_MODULE_VERSION;
860-
861-
#ifndef EXTERNAL_NAPI
862-
if (!node::load_napi_modules) {
863-
// NAPI is disabled, so set the module version to -1 to cause the module
864-
// to be unloaded.
865-
module_version = -1;
866-
}
867-
#endif // EXTERNAL_NAPI
868-
869851
node::node_module* nm = new node::node_module {
870-
module_version,
852+
-1,
871853
mod->nm_flags,
872854
nullptr,
873855
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

+2-2
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(
18-
'FATAL ERROR: test_fatal::Test fatal message'));
18+
'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)
Please sign in to comment.