mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
doc: use ESM syntax for WASI example
PR-URL: https://github.com/nodejs/node/pull/36848 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com>
This commit is contained in:
1 parent
8dc8adc782
commit
707b97307d
2 files changed
+7
-8
No files matched your search
@@ -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',
|
||||
|
||||
+6
-8
@@ -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');
|
||||
const { WASI } = require('wasi');
|
||||
import fs from 'fs';
|
||||
import { WASI } from 'wasi';
|
||||
|
||||
const wasi = new WASI({
|
||||
args: process.argv,
|
||||
env: process.env,
|
||||
@@ -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'));
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user