Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit ab6f437

Browse files
committed
wasi: put wasi behind a flag
This commit puts the WASI implementation behind a --experimental-wasi CLI flag, and prints an experimental warning on first use of WASI. It also includes some misc cleanup.
1 parent d511681 commit ab6f437

File tree

10 files changed

+36
-4
lines changed

10 files changed

+36
-4
lines changed

doc/api/cli.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ added: v9.6.0
220220

221221
Enable experimental ES Module support in the `vm` module.
222222

223+
### `--experimental-wasi`
224+
<!-- YAML
225+
added: REPLACEME
226+
-->
227+
228+
Enable experimental WebAssembly System Interface (WASI) support.
229+
223230
### `--experimental-wasm-modules`
224231
<!-- YAML
225232
added: v12.3.0
@@ -1029,6 +1036,7 @@ Node.js options that are allowed are:
10291036
* `--experimental-report`
10301037
* `--experimental-resolve-self`
10311038
* `--experimental-vm-modules`
1039+
* `--experimental-wasi`
10321040
* `--experimental-wasm-modules`
10331041
* `--force-context-aware`
10341042
* `--force-fips`

lib/internal/bootstrap/loaders.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ function NativeModule(id) {
155155
this.loaded = false;
156156
this.loading = false;
157157
this.canBeRequiredByUsers = !id.startsWith('internal/');
158+
159+
if (id === 'wasi')
160+
this.canBeRequiredByUsers = !!internalBinding('config').experimentalWasi;
158161
}
159162

160163
// To be called during pre-execution when --expose-internals is on.

lib/internal/modules/cjs/helpers.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ const builtinLibs = [
119119
'v8', 'vm', 'worker_threads', 'zlib'
120120
];
121121

122+
if (internalBinding('config').experimentalWasi) {
123+
builtinLibs.push('wasi');
124+
builtinLibs.sort();
125+
}
126+
122127
if (typeof internalBinding('inspector').open === 'function') {
123128
builtinLibs.push('inspector');
124129
builtinLibs.sort();

lib/wasi.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
// TODO(cjihrig): Put WASI behind a flag.
21
'use strict';
32
/* global WebAssembly */
43
const { Array, ArrayPrototype, Object } = primordials;
54
const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes;
5+
const { emitExperimentalWarning } = require('internal/util');
66
const { WASI: _WASI } = internalBinding('wasi');
77
const kSetMemory = Symbol('setMemory');
88

9+
emitExperimentalWarning('WASI');
10+
911

1012
class WASI {
1113
constructor(options = {}) {

src/node_config.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ static void Initialize(Local<Object> target,
8484

8585
READONLY_PROPERTY(target, "hasCachedBuiltins",
8686
v8::Boolean::New(isolate, native_module::has_code_cache));
87+
88+
if (per_process::cli_options->per_isolate->per_env->experimental_wasi)
89+
READONLY_TRUE_PROPERTY(target, "experimentalWasi");
8790
} // InitConfig
8891

8992
} // namespace node

src/node_options.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
368368
&EnvironmentOptions::experimental_report,
369369
kAllowedInEnvironment);
370370
#endif // NODE_REPORT
371+
AddOption("--experimental-wasi",
372+
"experimental WASI support",
373+
&EnvironmentOptions::experimental_wasi,
374+
kAllowedInEnvironment);
371375
AddOption("--expose-internals", "", &EnvironmentOptions::expose_internals);
372376
AddOption("--frozen-intrinsics",
373377
"experimental frozen intrinsics support",

src/node_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class EnvironmentOptions : public Options {
151151
#ifdef NODE_REPORT
152152
bool experimental_report = false;
153153
#endif // NODE_REPORT
154+
bool experimental_wasi = false;
154155
std::string eval_string;
155156
bool print_eval = false;
156157
bool force_repl = false;

src/node_wasi.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,12 @@ using v8::Value;
8181
WASI::WASI(Environment* env,
8282
Local<Object> object,
8383
uvwasi_options_t* options) : BaseObject(env, object) {
84-
/* uvwasi_errno_t err = */ uvwasi_init(&uvw_, options);
84+
CHECK_EQ(uvwasi_init(&uvw_, options), UVWASI_ESUCCESS);
8585
memory_.Reset();
8686
}
8787

8888

8989
WASI::~WASI() {
90-
/* TODO(cjihrig): Free memory. */
9190
uvwasi_destroy(&uvw_);
9291
}
9392

test/wasi/test-wasi-binding.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --experimental-wasi
12
'use strict';
23

34
const common = require('../common');

test/wasi/test-wasi.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33

44
if (process.argv[2] === 'wasi-child') {
55
const fixtures = require('../common/fixtures');
66
const tmpdir = require('../../test/common/tmpdir');
77
const fs = require('fs');
88
const path = require('path');
9+
10+
common.expectWarning('ExperimentalWarning',
11+
'WASI is an experimental feature. This feature could ' +
12+
'change at any time');
13+
914
const { WASI } = require('wasi');
1015
tmpdir.refresh();
1116
const wasmDir = path.join(__dirname, 'wasm');
@@ -38,6 +43,7 @@ if (process.argv[2] === 'wasi-child') {
3843
opts.input = options.stdin;
3944

4045
const child = cp.spawnSync(process.execPath, [
46+
'--experimental-wasi',
4147
'--experimental-wasm-bigint',
4248
__filename,
4349
'wasi-child',

0 commit comments

Comments
 (0)