Browse Source

n-api: remove n-api module loading flag

Remove the command line flag that was needed for N-API module loading.
Re: https://github.com/nodejs/vm/issues/9

PR-URL: https://github.com/nodejs/node/pull/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>
canary-base
Gabriel Schulhof 8 years ago
committed by Michael Dawson
parent
commit
a8c0a43a22
  1. 9
      doc/api/cli.md
  2. 8
      doc/api/n-api.md
  3. 1
      src/env-inl.h
  4. 6
      src/env.cc
  5. 2
      src/env.h
  6. 48
      src/node.cc
  7. 20
      src/node_api.cc
  8. 2
      test/addons-napi/test_async/test.js
  9. 2
      test/addons-napi/test_fatal/test.js
  10. 4
      test/addons-napi/test_function/test_function.c
  11. 12
      test/addons-napi/test_warning/binding.gyp
  12. 18
      test/addons-napi/test_warning/test.js
  13. 11
      test/addons-napi/test_warning/test_warning.c
  14. 11
      test/addons-napi/test_warning/test_warning2.c
  15. 2
      test/addons-napi/testcfg.py

9
doc/api/cli.md

@ -178,14 +178,6 @@ added: v8.4.0
Enable the experimental `'http2'` module. Enable the experimental `'http2'` module.
### `--napi-modules`
<!-- YAML
added: v8.0.0
-->
Enable loading native modules compiled with the ABI-stable Node.js API (N-API)
(experimental).
### `--abort-on-uncaught-exception` ### `--abort-on-uncaught-exception`
<!-- YAML <!-- YAML
added: v0.10 added: v0.10
@ -453,7 +445,6 @@ Node options that are allowed are:
- `--inspect-brk` - `--inspect-brk`
- `--inspect-port` - `--inspect-port`
- `--inspect` - `--inspect`
- `--napi-modules`
- `--no-deprecation` - `--no-deprecation`
- `--no-warnings` - `--no-warnings`
- `--openssl-config` - `--openssl-config`

8
doc/api/n-api.md

@ -63,14 +63,6 @@ For example:
#include <node_api.h> #include <node_api.h>
``` ```
As the feature is experimental it must be enabled with the
following command line
[option](https://nodejs.org/dist/latest-v8.x/docs/api/cli.html#cli_napi_modules):
```bash
--napi-modules
```
## Basic N-API Data Types ## Basic N-API Data Types
N-API exposes the following fundamental datatypes as abstractions that are N-API exposes the following fundamental datatypes as abstractions that are

1
src/env-inl.h

@ -288,6 +288,7 @@ inline Environment::Environment(IsolateData* isolate_data,
printed_error_(false), printed_error_(false),
trace_sync_io_(false), trace_sync_io_(false),
abort_on_uncaught_exception_(false), abort_on_uncaught_exception_(false),
emit_napi_warning_(true),
makecallback_cntr_(0), makecallback_cntr_(0),
#if HAVE_INSPECTOR #if HAVE_INSPECTOR
inspector_agent_(this), inspector_agent_(this),

6
src/env.cc

@ -213,6 +213,12 @@ bool Environment::RemovePromiseHook(promise_hook_func fn, void* arg) {
return true; return true;
} }
bool Environment::EmitNapiWarning() {
bool current_value = emit_napi_warning_;
emit_napi_warning_ = false;
return current_value;
}
void Environment::EnvPromiseHook(v8::PromiseHookType type, void Environment::EnvPromiseHook(v8::PromiseHookType type,
v8::Local<v8::Promise> promise, v8::Local<v8::Promise> promise,
v8::Local<v8::Value> parent) { v8::Local<v8::Value> parent) {

2
src/env.h

@ -669,6 +669,7 @@ class Environment {
void AddPromiseHook(promise_hook_func fn, void* arg); void AddPromiseHook(promise_hook_func fn, void* arg);
bool RemovePromiseHook(promise_hook_func fn, void* arg); bool RemovePromiseHook(promise_hook_func fn, void* arg);
bool EmitNapiWarning();
private: private:
inline void ThrowError(v8::Local<v8::Value> (*fun)(v8::Local<v8::String>), inline void ThrowError(v8::Local<v8::Value> (*fun)(v8::Local<v8::String>),
@ -690,6 +691,7 @@ class Environment {
bool printed_error_; bool printed_error_;
bool trace_sync_io_; bool trace_sync_io_;
bool abort_on_uncaught_exception_; bool abort_on_uncaught_exception_;
bool emit_napi_warning_;
size_t makecallback_cntr_; size_t makecallback_cntr_;
std::vector<double> destroy_ids_list_; std::vector<double> destroy_ids_list_;

48
src/node.cc

@ -197,9 +197,6 @@ unsigned int reverted = 0;
std::string icu_data_dir; // NOLINT(runtime/string) std::string icu_data_dir; // NOLINT(runtime/string)
#endif #endif
// N-API is in experimental state, disabled by default.
bool load_napi_modules = false;
// used by C++ modules as well // used by C++ modules as well
bool no_deprecation = false; bool no_deprecation = false;
@ -2703,27 +2700,22 @@ static void DLOpen(const FunctionCallbackInfo<Value>& args) {
env->ThrowError("Module did not self-register."); env->ThrowError("Module did not self-register.");
return; return;
} }
if (mp->nm_version != NODE_MODULE_VERSION) { if (mp->nm_version == -1) {
char errmsg[1024]; if (env->EmitNapiWarning()) {
if (mp->nm_version == -1) { ProcessEmitWarning(env, "N-API is an experimental feature and could "
snprintf(errmsg, "change at any time.");
sizeof(errmsg),
"The module '%s'"
"\nwas compiled against the ABI-stable Node.js API (N-API)."
"\nThis feature is experimental and must be enabled on the "
"\ncommand-line by adding --napi-modules.",
*filename);
} else {
snprintf(errmsg,
sizeof(errmsg),
"The module '%s'"
"\nwas compiled against a different Node.js version using"
"\nNODE_MODULE_VERSION %d. This version of Node.js requires"
"\nNODE_MODULE_VERSION %d. Please try re-compiling or "
"re-installing\nthe module (for instance, using `npm rebuild` "
"or `npm install`).",
*filename, mp->nm_version, NODE_MODULE_VERSION);
} }
} else if (mp->nm_version != NODE_MODULE_VERSION) {
char errmsg[1024];
snprintf(errmsg,
sizeof(errmsg),
"The module '%s'"
"\nwas compiled against a different Node.js version using"
"\nNODE_MODULE_VERSION %d. This version of Node.js requires"
"\nNODE_MODULE_VERSION %d. Please try re-compiling or "
"re-installing\nthe module (for instance, using `npm rebuild` "
"or `npm install`).",
*filename, mp->nm_version, NODE_MODULE_VERSION);
// NOTE: `mp` is allocated inside of the shared library's memory, calling // NOTE: `mp` is allocated inside of the shared library's memory, calling
// `dlclose` will deallocate it // `dlclose` will deallocate it
@ -3822,7 +3814,8 @@ static void PrintHelp() {
" --throw-deprecation throw an exception on deprecations\n" " --throw-deprecation throw an exception on deprecations\n"
" --pending-deprecation emit pending deprecation warnings\n" " --pending-deprecation emit pending deprecation warnings\n"
" --no-warnings silence all process warnings\n" " --no-warnings silence all process warnings\n"
" --napi-modules load N-API modules\n" " --napi-modules load N-API modules (no-op - option\n"
" kept for compatibility)\n"
" --abort-on-uncaught-exception\n" " --abort-on-uncaught-exception\n"
" aborting instead of exiting causes a\n" " aborting instead of exiting causes a\n"
" core file to be generated for analysis\n" " core file to be generated for analysis\n"
@ -4080,7 +4073,7 @@ static void ParseArgs(int* argc,
} else if (strcmp(arg, "--no-deprecation") == 0) { } else if (strcmp(arg, "--no-deprecation") == 0) {
no_deprecation = true; no_deprecation = true;
} else if (strcmp(arg, "--napi-modules") == 0) { } else if (strcmp(arg, "--napi-modules") == 0) {
load_napi_modules = true; // no-op
} else if (strcmp(arg, "--no-warnings") == 0) { } else if (strcmp(arg, "--no-warnings") == 0) {
no_process_warnings = true; no_process_warnings = true;
} else if (strcmp(arg, "--trace-warnings") == 0) { } else if (strcmp(arg, "--trace-warnings") == 0) {
@ -4735,11 +4728,6 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data,
env.set_trace_sync_io(trace_sync_io); env.set_trace_sync_io(trace_sync_io);
if (load_napi_modules) {
ProcessEmitWarning(&env, "N-API is an experimental feature "
"and could change at any time.");
}
{ {
SealHandleScope seal(isolate); SealHandleScope seal(isolate);
bool more; bool more;

20
src/node_api.cc

@ -841,28 +841,10 @@ void napi_module_register_cb(v8::Local<v8::Object> exports,
} // end of anonymous namespace } // end of anonymous namespace
#ifndef EXTERNAL_NAPI
namespace node {
// Indicates whether NAPI was enabled/disabled via the node command-line.
extern bool load_napi_modules;
}
#endif // EXTERNAL_NAPI
// Registers a NAPI module. // Registers a NAPI module.
void napi_module_register(napi_module* mod) { void napi_module_register(napi_module* mod) {
// NAPI modules always work with the current node version.
int module_version = NODE_MODULE_VERSION;
#ifndef EXTERNAL_NAPI
if (!node::load_napi_modules) {
// NAPI is disabled, so set the module version to -1 to cause the module
// to be unloaded.
module_version = -1;
}
#endif // EXTERNAL_NAPI
node::node_module* nm = new node::node_module { node::node_module* nm = new node::node_module {
module_version, -1,
mod->nm_flags, mod->nm_flags,
nullptr, nullptr,
mod->nm_filename, mod->nm_filename,

2
test/addons-napi/test_async/test.js

@ -15,7 +15,7 @@ if (process.argv[2] === 'child') {
return; return;
} }
const p = child_process.spawnSync( const p = child_process.spawnSync(
process.execPath, [ '--napi-modules', __filename, 'child' ]); process.execPath, [ __filename, 'child' ]);
assert.ifError(p.error); assert.ifError(p.error);
assert.ok(p.stderr.toString().includes(testException)); assert.ok(p.stderr.toString().includes(testException));

2
test/addons-napi/test_fatal/test.js

@ -12,7 +12,7 @@ if (process.argv[2] === 'child') {
} }
const p = child_process.spawnSync( const p = child_process.spawnSync(
process.execPath, [ '--napi-modules', __filename, 'child' ]); process.execPath, [ __filename, 'child' ]);
assert.ifError(p.error); assert.ifError(p.error);
assert.ok(p.stderr.toString().includes( assert.ok(p.stderr.toString().includes(
'FATAL ERROR: test_fatal::Test fatal message')); 'FATAL ERROR: test_fatal::Test fatal message'));

4
test/addons-napi/test_function/test_function.c

@ -26,7 +26,9 @@ napi_value TestCallFunction(napi_env env, napi_callback_info info) {
return result; return result;
} }
void TestFunctionName(napi_env env, napi_callback_info info) {} napi_value TestFunctionName(napi_env env, napi_callback_info info) {
return NULL;
}
napi_value Init(napi_env env, napi_value exports) { napi_value Init(napi_env env, napi_value exports) {
napi_value fn1; napi_value fn1;

12
test/addons-napi/test_warning/binding.gyp

@ -0,0 +1,12 @@
{
"targets": [
{
"target_name": "test_warning",
"sources": [ "test_warning.c" ]
},
{
"target_name": "test_warning2",
"sources": [ "test_warning2.c" ]
}
]
}

18
test/addons-napi/test_warning/test.js

@ -0,0 +1,18 @@
'use strict';
if (process.argv[2] === 'child') {
const common = require('../../common');
console.log(require(`./build/${common.buildType}/test_warning`));
console.log(require(`./build/${common.buildType}/test_warning2`));
} else {
const run = require('child_process').spawnSync;
const assert = require('assert');
const warning = 'Warning: N-API is an experimental feature and could ' +
'change at any time.';
const result = run(process.execPath, [__filename, 'child']);
assert.deepStrictEqual(result.stdout.toString().match(/\S+/g), ['42', '1337'],
'Modules loaded correctly');
assert.deepStrictEqual(result.stderr.toString().split(warning).length, 2,
'Warning was displayed only once');
}

11
test/addons-napi/test_warning/test_warning.c

@ -0,0 +1,11 @@
#include <node_api.h>
#include "../common.h"
napi_value Init(napi_env env, napi_value exports) {
napi_value result;
NAPI_CALL(env,
napi_create_uint32(env, 42, &result));
return result;
}
NAPI_MODULE(test_warning, Init)

11
test/addons-napi/test_warning/test_warning2.c

@ -0,0 +1,11 @@
#include <node_api.h>
#include "../common.h"
napi_value Init(napi_env env, napi_value exports) {
napi_value result;
NAPI_CALL(env,
napi_create_uint32(env, 1337, &result));
return result;
}
NAPI_MODULE(test_warning2, Init)

2
test/addons-napi/testcfg.py

@ -3,4 +3,4 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import testpy import testpy
def GetConfiguration(context, root): def GetConfiguration(context, root):
return testpy.AddonTestConfiguration(context, root, 'addons-napi', ['--napi-modules']) return testpy.AddonTestConfiguration(context, root, 'addons-napi')

Loading…
Cancel
Save