mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -05:00
BREAKING(std/wasi): rename Module to Context (#7110)
This commit renames Module and ModuleOptions to context to avoid stutter confusion, e.g avoid having documentation that says things like instantiate the snapshot's module's module.
This commit is contained in:
parent
c1d543e10a
commit
e8968e6bf4
3 changed files with 11 additions and 11 deletions
|
@ -55,9 +55,9 @@ This module provides an implementation of the WebAssembly System Interface
|
|||
## Usage
|
||||
|
||||
```typescript
|
||||
import WASI from "https://deno.land/std/wasi/snapshot_preview1.ts";
|
||||
import Context from "https://deno.land/std/wasi/snapshot_preview1.ts";
|
||||
|
||||
const wasi = new WASI({
|
||||
const context = new Context({
|
||||
args: Deno.args,
|
||||
env: Deno.env,
|
||||
});
|
||||
|
@ -65,10 +65,10 @@ const wasi = new WASI({
|
|||
const binary = await Deno.readFile("path/to/your/module.wasm");
|
||||
const module = await WebAssembly.compile(binary);
|
||||
const instance = await WebAssembly.instantiate(module, {
|
||||
wasi_snapshot_preview1: wasi.exports,
|
||||
wasi_snapshot_preview1: context.exports,
|
||||
});
|
||||
|
||||
wasi.memory = instance.exports.memory;
|
||||
context.memory = context.exports.memory;
|
||||
|
||||
if (module.exports._start) {
|
||||
instance.exports._start();
|
||||
|
|
|
@ -277,14 +277,14 @@ function errno(err: Error) {
|
|||
}
|
||||
}
|
||||
|
||||
export interface ModuleOptions {
|
||||
export interface ContextOptions {
|
||||
args?: string[];
|
||||
env?: { [key: string]: string | undefined };
|
||||
preopens?: { [key: string]: string };
|
||||
memory?: WebAssembly.Memory;
|
||||
}
|
||||
|
||||
export default class Module {
|
||||
export default class Context {
|
||||
args: string[];
|
||||
env: { [key: string]: string | undefined };
|
||||
memory: WebAssembly.Memory;
|
||||
|
@ -294,7 +294,7 @@ export default class Module {
|
|||
|
||||
exports: Record<string, Function>;
|
||||
|
||||
constructor(options: ModuleOptions) {
|
||||
constructor(options: ContextOptions) {
|
||||
this.args = options.args ? options.args : [];
|
||||
this.env = options.env ? options.env : {};
|
||||
this.memory = options.memory!;
|
||||
|
|
|
@ -2,24 +2,24 @@
|
|||
|
||||
import { assert, assertEquals } from "../testing/asserts.ts";
|
||||
import * as path from "../path/mod.ts";
|
||||
import WASI from "./snapshot_preview1.ts";
|
||||
import Context from "./snapshot_preview1.ts";
|
||||
|
||||
if (import.meta.main) {
|
||||
const options = JSON.parse(Deno.args[0]);
|
||||
const binary = await Deno.readFile(Deno.args[1]);
|
||||
const module = await WebAssembly.compile(binary);
|
||||
|
||||
const wasi = new WASI({
|
||||
const context = new Context({
|
||||
env: options.env,
|
||||
args: options.args,
|
||||
preopens: options.preopens,
|
||||
});
|
||||
|
||||
const instance = new WebAssembly.Instance(module, {
|
||||
wasi_snapshot_preview1: wasi.exports,
|
||||
wasi_snapshot_preview1: context.exports,
|
||||
});
|
||||
|
||||
wasi.memory = instance.exports.memory;
|
||||
context.memory = instance.exports.memory;
|
||||
|
||||
instance.exports._start();
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue