Notable changes:
* fs:
* Reworked experimental recursive `rmdir()` (cjihrig)
https://github.com/nodejs/node/pull/30644
* The `maxBusyTries` option is renamed to `maxRetries`, and its
default is set to 0. The `emfileWait` option has been removed,
and `EMFILE` errors use the same retry logic as other errors.
The `retryDelay` option is now supported. `ENFILE` errors are
now retried.
* http:
* Make maximum header size configurable per-stream or per-server
(Anna Henningsen) https://github.com/nodejs/node/pull/30570
* http2:
* Make maximum tolerated rejected streams configurable (Denys
Otrishko) https://github.com/nodejs/node/pull/30534
* Allow to configure maximum tolerated invalid frames (Denys
Otrishko) https://github.com/nodejs/node/pull/30534
* wasi:
* Introduce initial WASI support (cjihrig)
https://github.com/nodejs/node/pull/30258
PR-URL: https://github.com/nodejs/node/pull/30774
3.1 KiB
WebAssembly System Interface (WASI)
Stability: 1 - Experimental
The WASI API provides an implementation of the WebAssembly System Interface specification. WASI gives sandboxed WebAssembly applications access to the underlying operating system via a collection of POSIX-like functions.
'use strict';
const fs = require('fs');
const { WASI } = require('wasi');
const wasi = new WASI({
args: process.argv,
env: process.env,
preopens: {
'/sandbox': '/some/real/path/that/wasm/can/access'
}
});
const importObject = { wasi_unstable: wasi.wasiImport };
(async () => {
const wasm = await WebAssembly.compile(fs.readFileSync('./binary.wasm'));
const instance = await WebAssembly.instantiate(wasm, importObject);
wasi.start(instance);
})();
The --experimental-wasi-unstable-preview0 and --experimental-wasm-bigint
CLI arguments are needed for the previous example to run.
Class: WASI
The WASI class provides the WASI system call API and additional convenience
methods for working with WASI-based applications. Each WASI instance
represents a distinct sandbox environment. For security purposes, each WASI
instance must have its command line arguments, environment variables, and
sandbox directory structure configured explicitly.
new WASI([options])
options{Object}args{Array} An array of strings that the WebAssembly application will see as command line arguments. The first argument is the virtual path to the WASI command itself. Default:[].env{Object} An object similar toprocess.envthat the WebAssembly application will see as its environment. Default:{}.preopens{Object} This object represents the WebAssembly application's sandbox directory structure. The string keys ofpreopensare treated as directories within the sandbox. The corresponding values inpreopensare the real paths to those directories on the host machine.
wasi.start(instance)
instance{WebAssembly.Instance}
Attempt to begin execution of instance by invoking its _start() export.
If instance does not contain a _start() export, then start() attempts to
invoke the __wasi_unstable_reactor_start() export. If neither of those exports
is present on instance, then start() does nothing.
start() requires that instance exports a WebAssembly.Memory named
memory. If instance does not have a memory export an exception is thrown.
wasi.wasiImport
- {Object}
wasiImport is an object that implements the WASI system call API. This object
should be passed as the wasi_unstable import during the instantiation of a
WebAssembly.Instance.