1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 08:33:43 -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:
Casper Beyer 2020-08-25 00:21:06 +08:00 committed by GitHub
parent c1d543e10a
commit e8968e6bf4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 11 deletions

View file

@ -55,9 +55,9 @@ This module provides an implementation of the WebAssembly System Interface
## Usage ## Usage
```typescript ```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, args: Deno.args,
env: Deno.env, env: Deno.env,
}); });
@ -65,10 +65,10 @@ const wasi = new WASI({
const binary = await Deno.readFile("path/to/your/module.wasm"); const binary = await Deno.readFile("path/to/your/module.wasm");
const module = await WebAssembly.compile(binary); const module = await WebAssembly.compile(binary);
const instance = await WebAssembly.instantiate(module, { 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) { if (module.exports._start) {
instance.exports._start(); instance.exports._start();

View file

@ -277,14 +277,14 @@ function errno(err: Error) {
} }
} }
export interface ModuleOptions { export interface ContextOptions {
args?: string[]; args?: string[];
env?: { [key: string]: string | undefined }; env?: { [key: string]: string | undefined };
preopens?: { [key: string]: string }; preopens?: { [key: string]: string };
memory?: WebAssembly.Memory; memory?: WebAssembly.Memory;
} }
export default class Module { export default class Context {
args: string[]; args: string[];
env: { [key: string]: string | undefined }; env: { [key: string]: string | undefined };
memory: WebAssembly.Memory; memory: WebAssembly.Memory;
@ -294,7 +294,7 @@ export default class Module {
exports: Record<string, Function>; exports: Record<string, Function>;
constructor(options: ModuleOptions) { constructor(options: ContextOptions) {
this.args = options.args ? options.args : []; this.args = options.args ? options.args : [];
this.env = options.env ? options.env : {}; this.env = options.env ? options.env : {};
this.memory = options.memory!; this.memory = options.memory!;

View file

@ -2,24 +2,24 @@
import { assert, assertEquals } from "../testing/asserts.ts"; import { assert, assertEquals } from "../testing/asserts.ts";
import * as path from "../path/mod.ts"; import * as path from "../path/mod.ts";
import WASI from "./snapshot_preview1.ts"; import Context from "./snapshot_preview1.ts";
if (import.meta.main) { if (import.meta.main) {
const options = JSON.parse(Deno.args[0]); const options = JSON.parse(Deno.args[0]);
const binary = await Deno.readFile(Deno.args[1]); const binary = await Deno.readFile(Deno.args[1]);
const module = await WebAssembly.compile(binary); const module = await WebAssembly.compile(binary);
const wasi = new WASI({ const context = new Context({
env: options.env, env: options.env,
args: options.args, args: options.args,
preopens: options.preopens, preopens: options.preopens,
}); });
const instance = new WebAssembly.Instance(module, { 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(); instance.exports._start();
} else { } else {