Skip to content
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

doc: use ESM syntax for WASI example #36848

Merged
merged 1 commit into from Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -57,6 +57,7 @@ module.exports = {
'doc/api/module.md',
'doc/api/modules.md',
'doc/api/packages.md',
'doc/api/wasi.md',
'test/es-module/test-esm-type-flag.js',
'test/es-module/test-esm-type-flag-alias.js',
'*.mjs',
Expand Down
14 changes: 6 additions & 8 deletions doc/api/wasi.md
Expand Up @@ -11,9 +11,9 @@ specification. WASI gives sandboxed WebAssembly applications access to the
underlying operating system via a collection of POSIX-like functions.

```js
'use strict';
const fs = require('fs');
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
const { WASI } = require('wasi');
import fs from 'fs';
import { WASI } from 'wasi';

const wasi = new WASI({
args: process.argv,
env: process.env,
Expand All @@ -23,12 +23,10 @@ const wasi = new WASI({
});
const importObject = { wasi_snapshot_preview1: wasi.wasiImport };

(async () => {
const wasm = await WebAssembly.compile(fs.readFileSync('./demo.wasm'));
const instance = await WebAssembly.instantiate(wasm, importObject);
const wasm = await WebAssembly.compile(fs.readFileSync('./demo.wasm'));
gengjiawen marked this conversation as resolved.
Show resolved Hide resolved
const instance = await WebAssembly.instantiate(wasm, importObject);

wasi.start(instance);
})();
wasi.start(instance);
```

To run the above example, create a new WebAssembly text format file named
Expand Down