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

Commit 7da2677

Browse files
committedOct 9, 2019
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 07bd0ec commit 7da2677

File tree

10 files changed

+36
-4
lines changed

10 files changed

+36
-4
lines changed
 

‎doc/api/cli.md

+8
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ added: v9.6.0
207207

208208
Enable experimental ES Module support in the `vm` module.
209209

210+
### `--experimental-wasi`
211+
<!-- YAML
212+
added: REPLACEME
213+
-->
214+
215+
Enable experimental WebAssembly System Interface (WASI) support.
216+
210217
### `--experimental-wasm-modules`
211218
<!-- YAML
212219
added: v12.3.0
@@ -1006,6 +1013,7 @@ Node.js options that are allowed are:
10061013
* `--experimental-repl-await`
10071014
* `--experimental-report`
10081015
* `--experimental-vm-modules`
1016+
* `--experimental-wasi`
10091017
* `--experimental-wasm-modules`
10101018
* `--force-context-aware`
10111019
* `--force-fips`

‎lib/internal/bootstrap/loaders.js

+3
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

+5
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

+3-1
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

+3
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

+4
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
369369
&EnvironmentOptions::experimental_report,
370370
kAllowedInEnvironment);
371371
#endif // NODE_REPORT
372+
AddOption("--experimental-wasi",
373+
"experimental WASI support",
374+
&EnvironmentOptions::experimental_wasi,
375+
kAllowedInEnvironment);
372376
AddOption("--expose-internals", "", &EnvironmentOptions::expose_internals);
373377
AddOption("--frozen-intrinsics",
374378
"experimental frozen intrinsics support",

‎src/node_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class EnvironmentOptions : public Options {
150150
#ifdef NODE_REPORT
151151
bool experimental_report = false;
152152
#endif // NODE_REPORT
153+
bool experimental_wasi = false;
153154
std::string eval_string;
154155
bool print_eval = false;
155156
bool force_repl = false;

‎src/node_wasi.cc

+1-2
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

+1
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

+7-1
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)