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

Commit

Permalink
wasi: put wasi behind a flag
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cjihrig committed Oct 15, 2019
1 parent dbf1131 commit 7c4ea57
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 4 deletions.
8 changes: 8 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ added: v9.6.0

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

### `--experimental-wasi`
<!-- YAML
added: REPLACEME
-->

Enable experimental WebAssembly System Interface (WASI) support.

### `--experimental-wasm-modules`
<!-- YAML
added: v12.3.0
Expand Down Expand Up @@ -998,6 +1005,7 @@ Node.js options that are allowed are:
* `--experimental-repl-await`
* `--experimental-report`
* `--experimental-vm-modules`
* `--experimental-wasi`
* `--experimental-wasm-modules`
* `--force-context-aware`
* `--force-fips`
Expand Down
3 changes: 3 additions & 0 deletions lib/internal/bootstrap/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ function NativeModule(id) {
this.loaded = false;
this.loading = false;
this.canBeRequiredByUsers = !id.startsWith('internal/');

if (id === 'wasi')
this.canBeRequiredByUsers = !!internalBinding('config').experimentalWasi;
}

// To be called during pre-execution when --expose-internals is on.
Expand Down
5 changes: 5 additions & 0 deletions lib/internal/modules/cjs/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ const builtinLibs = [
'v8', 'vm', 'worker_threads', 'zlib'
];

if (internalBinding('config').experimentalWasi) {
builtinLibs.push('wasi');
builtinLibs.sort();
}

if (typeof internalBinding('inspector').open === 'function') {
builtinLibs.push('inspector');
builtinLibs.sort();
Expand Down
4 changes: 3 additions & 1 deletion lib/wasi.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// TODO(cjihrig): Put WASI behind a flag.
'use strict';
/* global WebAssembly */
const { Array, ArrayPrototype, Object } = primordials;
const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes;
const { emitExperimentalWarning } = require('internal/util');
const { WASI: _WASI } = internalBinding('wasi');
const kSetMemory = Symbol('setMemory');

emitExperimentalWarning('WASI');


class WASI {
constructor(options = {}) {
Expand Down
3 changes: 3 additions & 0 deletions src/node_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ static void Initialize(Local<Object> target,

READONLY_PROPERTY(target, "hasCachedBuiltins",
v8::Boolean::New(isolate, native_module::has_code_cache));

if (per_process::cli_options->per_isolate->per_env->experimental_wasi)
READONLY_TRUE_PROPERTY(target, "experimentalWasi");
} // InitConfig

} // namespace node
Expand Down
4 changes: 4 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
&EnvironmentOptions::experimental_report,
kAllowedInEnvironment);
#endif // NODE_REPORT
AddOption("--experimental-wasi",
"experimental WASI support",
&EnvironmentOptions::experimental_wasi,
kAllowedInEnvironment);
AddOption("--expose-internals", "", &EnvironmentOptions::expose_internals);
AddOption("--frozen-intrinsics",
"experimental frozen intrinsics support",
Expand Down
1 change: 1 addition & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class EnvironmentOptions : public Options {
#ifdef NODE_REPORT
bool experimental_report = false;
#endif // NODE_REPORT
bool experimental_wasi = false;
std::string eval_string;
bool print_eval = false;
bool force_repl = false;
Expand Down
3 changes: 1 addition & 2 deletions src/node_wasi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,12 @@ using v8::Value;
WASI::WASI(Environment* env,
Local<Object> object,
uvwasi_options_t* options) : BaseObject(env, object) {
/* uvwasi_errno_t err = */ uvwasi_init(&uvw_, options);
CHECK_EQ(uvwasi_init(&uvw_, options), UVWASI_ESUCCESS);
memory_.Reset();
}


WASI::~WASI() {
/* TODO(cjihrig): Free memory. */
uvwasi_destroy(&uvw_);
}

Expand Down
1 change: 1 addition & 0 deletions test/wasi/test-wasi-binding.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Flags: --experimental-wasi
'use strict';

const common = require('../common');
Expand Down
8 changes: 7 additions & 1 deletion test/wasi/test-wasi.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
'use strict';
require('../common');
const common = require('../common');

if (process.argv[2] === 'wasi-child') {
const fixtures = require('../common/fixtures');
const tmpdir = require('../../test/common/tmpdir');
const fs = require('fs');
const path = require('path');

common.expectWarning('ExperimentalWarning',
'WASI is an experimental feature. This feature could ' +
'change at any time');

const { WASI } = require('wasi');
tmpdir.refresh();
const wasmDir = path.join(__dirname, 'wasm');
Expand Down Expand Up @@ -38,6 +43,7 @@ if (process.argv[2] === 'wasi-child') {
opts.input = options.stdin;

const child = cp.spawnSync(process.execPath, [
'--experimental-wasi',
'--experimental-wasm-bigint',
__filename,
'wasi-child',
Expand Down

0 comments on commit 7c4ea57

Please sign in to comment.