Skip to content

esm: unflag --experimental-wasm-modules #57038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ If a file is found, its path will be passed to the

* The program was started with a command-line flag that forces the entry
point to be loaded with ECMAScript module loader, such as `--import`.
* The file has an `.mjs` or `.wasm` (with `--experimental-wasm-modules`)
extension.
* The file has an `.mjs` or `.wasm` extension.
* The file does not have a `.cjs` extension, and the nearest parent
`package.json` file contains a top-level [`"type"`][] field with a value of
`"module"`.
Expand All @@ -49,7 +48,6 @@ entry point, the `node` command will accept as input only files with `.js`,
`.mjs`, or `.cjs` extensions. With the following flags, additional file
extensions are enabled:

* [`--experimental-wasm-modules`][] for files with `.wasm` extension.
* [`--experimental-addon-modules`][] for files with `.node` extension.

## Options
Expand Down Expand Up @@ -1255,14 +1253,6 @@ changes:

Enable experimental WebAssembly System Interface (WASI) support.

### `--experimental-wasm-modules`

<!-- YAML
added: v12.3.0
-->

Enable experimental WebAssembly module support.

### `--experimental-webstorage`

<!-- YAML
Expand Down Expand Up @@ -3404,7 +3394,6 @@ one is included in the list below.
* `--experimental-transform-types`
* `--experimental-vm-modules`
* `--experimental-wasi-unstable-preview1`
* `--experimental-wasm-modules`
* `--experimental-webstorage`
* `--force-context-aware`
* `--force-fips`
Expand Down Expand Up @@ -3984,7 +3973,6 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
[`--env-file`]: #--env-fileconfig
[`--experimental-addon-modules`]: #--experimental-addon-modules
[`--experimental-sea-config`]: single-executable-applications.md#generating-single-executable-preparation-blobs
[`--experimental-wasm-modules`]: #--experimental-wasm-modules
[`--heap-prof-dir`]: #--heap-prof-dir
[`--import`]: #--importmodule
[`--no-experimental-strip-types`]: #--no-experimental-strip-types
Expand Down
64 changes: 38 additions & 26 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -705,34 +705,23 @@ imported from the same path.

## Wasm modules

> Stability: 1 - Experimental
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/57038
description: Wasm modules no longer require the `--experimental-wasm-modules` flag.
-->

Importing both WebAssembly module instances and WebAssembly source phase
imports are supported under the `--experimental-wasm-modules` flag.
imports is supported.

Both of these integrations are in line with the
[ES Module Integration Proposal for WebAssembly][].

Instance imports allow any `.wasm` files to be imported as normal modules,
supporting their module imports in turn.

For example, an `index.js` containing:

```js
import * as M from './library.wasm';
console.log(M);
```

executed under:

```bash
node --experimental-wasm-modules index.mjs
```

would provide the exports interface for the instantiation of `library.wasm`.

### Wasm Source Phase Imports

> Stability: 1.2 - Release candidate

<!-- YAML
added: v24.0.0
-->
Expand Down Expand Up @@ -766,6 +755,8 @@ const instance = await WebAssembly.instantiate(dynamicLibrary, importObject);

### JavaScript String Builtins

> Stability: 1.2 - Release candidate

<!-- YAML
added: REPLACEME
-->
Expand Down Expand Up @@ -815,14 +806,36 @@ const { exports: { getLength } } = await WebAssembly.instantiate(mod, {});
getLength('foo'); // Also returns 3.
```

### Wasm Instance Phase Imports

> Stability: 1.1 - Active development

Instance imports allow any `.wasm` files to be imported as normal modules,
supporting their module imports in turn.

For example, an `index.js` containing:

```js
import * as M from './library.wasm';
console.log(M);
```

executed under:

```bash
node index.mjs
```

would provide the exports interface for the instantiation of `library.wasm`.

### Reserved Wasm Namespaces

<!-- YAML
added: REPLACEME
-->

When importing WebAssembly modules through the ESM Integration, they cannot use
import module names or import/export names that start with reserved prefixes:
When importing WebAssembly module instances, they cannot use import module
names or import/export names that start with reserved prefixes:

* `wasm-js:` - reserved in all module import names, module names and export
names.
Expand Down Expand Up @@ -1189,7 +1202,7 @@ _isImports_, _conditions_)
> 1. Return _"commonjs"_.
> 4. If _url_ ends in _".json"_, then
> 1. Return _"json"_.
> 5. If `--experimental-wasm-modules` is enabled and _url_ ends in
> 5. If _url_ ends in
> _".wasm"_, then
> 1. Return _"wasm"_.
> 6. If `--experimental-addon-modules` is enabled and _url_ ends in
Expand All @@ -1207,9 +1220,8 @@ _isImports_, _conditions_)
> 1. Return _"module"_.
> 3. Return _"commonjs"_.
> 12. If _url_ does not have any extension, then
> 1. If _packageType_ is _"module"_ and `--experimental-wasm-modules` is
> enabled and the file at _url_ contains the header for a WebAssembly
> module, then
> 1. If _packageType_ is _"module"_ and the file at _url_ contains the
> "application/wasm" content type header for a WebAssembly module, then
> 1. Return _"wasm"_.
> 2. If _packageType_ is not **null**, then
> 1. Return _packageType_.
Expand Down
3 changes: 0 additions & 3 deletions doc/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@
"experimental-vm-modules": {
"type": "boolean"
},
"experimental-wasm-modules": {
"type": "boolean"
},
"experimental-websocket": {
"type": "boolean"
},
Expand Down
3 changes: 0 additions & 3 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ Enable experimental ES module support in VM module.
Enable experimental WebAssembly System Interface support. This
flag is no longer required as WASI is enabled by default.
.
.It Fl -experimental-wasm-modules
Enable experimental WebAssembly module support.
.
.It Fl -experimental-quic
Enable the experimental QUIC support.
.
Expand Down
9 changes: 2 additions & 7 deletions lib/internal/modules/esm/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const { getValidatedPath } = require('internal/fs/utils');
const fsBindings = internalBinding('fs');
const { internal: internalConstants } = internalBinding('constants');

const experimentalWasmModules = getOptionValue('--experimental-wasm-modules');
const experimentalAddonModules = getOptionValue('--experimental-addon-modules');

const extensionFormatMap = {
Expand All @@ -18,12 +17,9 @@ const extensionFormatMap = {
'.js': 'module',
'.json': 'json',
'.mjs': 'module',
'.wasm': 'wasm',
};

if (experimentalWasmModules) {
extensionFormatMap['.wasm'] = 'wasm';
}

if (experimentalAddonModules) {
extensionFormatMap['.node'] = 'addon';
}
Expand All @@ -46,7 +42,7 @@ function mimeToFormat(mime) {
) !== null
) { return 'module'; }
if (mime === 'application/json') { return 'json'; }
if (experimentalWasmModules && mime === 'application/wasm') { return 'wasm'; }
if (mime === 'application/wasm') { return 'wasm'; }
return null;
}

Expand All @@ -58,7 +54,6 @@ function mimeToFormat(mime) {
* @returns {'wasm'|'module'}
*/
function getFormatOfExtensionlessFile(url) {
if (!experimentalWasmModules) { return 'module'; }
const path = getValidatedPath(url);
switch (fsBindings.getFormatOfExtensionlessFile(path)) {
case internalConstants.EXTENSIONLESS_FORMAT_WASM:
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,6 @@ translators.set('json', function jsonStrategy(url, source) {
*/
const wasmInstances = new SafeWeakMap();
translators.set('wasm', async function(url, source) {
emitExperimentalWarning('Importing WebAssembly modules');

assertBufferSource(source, false, 'load');

debug(`Translating WASMModule ${url}`);
Expand Down Expand Up @@ -546,6 +544,7 @@ translators.set('wasm', async function(url, source) {
const createDynamicModule = require('internal/modules/esm/create_dynamic_module');

const { module } = createDynamicModule([...importsList], [...exportsList], url, (reflect) => {
emitExperimentalWarning('Importing WebAssembly module instances');
for (const impt of importsList) {
const importNs = reflect.imports[impt];
const wasmInstance = wasmInstances.get(importNs);
Expand Down
4 changes: 1 addition & 3 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -773,9 +773,7 @@ static ExitCode ProcessGlobalArgsInternal(std::vector<std::string>* args,
env_opts->abort_on_uncaught_exception = true;
}

if (env_opts->experimental_wasm_modules) {
v8_args.emplace_back("--js-source-phase-imports");
}
v8_args.emplace_back("--js-source-phase-imports");

#ifdef __POSIX__
// Block SIGPROF signals when sleeping in epoll_wait/kevent/etc. Avoids the
Expand Down
5 changes: 1 addition & 4 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
kAllowedInEnvvar);
AddAlias("--loader", "--experimental-loader");
AddOption("--experimental-modules", "", NoOp{}, kAllowedInEnvvar);
AddOption("--experimental-wasm-modules",
"experimental ES Module support for webassembly modules",
&EnvironmentOptions::experimental_wasm_modules,
kAllowedInEnvvar);
AddOption("--experimental-wasm-modules", "", NoOp{}, kAllowedInEnvvar);
AddOption("--experimental-import-meta-resolve",
"experimental ES Module import.meta.resolve() parentURL support",
&EnvironmentOptions::experimental_import_meta_resolve,
Expand Down
1 change: 0 additions & 1 deletion src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ class EnvironmentOptions : public Options {
std::string localstorage_file;
bool experimental_global_navigator = true;
bool experimental_global_web_crypto = true;
bool experimental_wasm_modules = false;
bool experimental_import_meta_resolve = false;
std::string input_type; // Value of --input-type
bool entry_is_url = false;
Expand Down
Loading
Loading