Skip to content

Commit

Permalink
Merge pull request #310 from wasmerio/fix-wasmer-js
Browse files Browse the repository at this point in the history
Correctly downcast RuntimeError through JsValue when extracting WASI exit codes
  • Loading branch information
Michael Bryan authored Dec 1, 2022
2 parents 44db664 + 9e55d0f commit 89c1e4c
Show file tree
Hide file tree
Showing 9 changed files with 531 additions and 340 deletions.
371 changes: 254 additions & 117 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ wasm-bindgen = "0.2.73"
wasmer = { version = "3.0.2", default-features = false, features = ["js", "std"] }
wasmer-wasi = { version = "3.0.2", default-features = false, features = ["js"] }
wasmer-vfs = { version = "3.0.2", default-features = false, features = ["mem-fs"] }
wasm-bindgen-downcast = "0.1.1"

[profile.release]
lto = true
opt-level = 'z'

# TODO(Michael-F-Bryan): Remove this when Wasmer 3.1 comes out
# See https://github.com/wasmerio/wasmer-js/issues/312 for more.
[patch.crates-io]
wasmer = { git = "https://github.com/wasmerio/wasmer", default-features = false, features = ["js", "std"], rev = "ecde2aa" }
wasmer-wasi = { git = "https://github.com/wasmerio/wasmer", default-features = false, features = ["js"], rev = "ecde2aa" }
wasmer-vfs = { git = "https://github.com/wasmerio/wasmer", default-features = false, features = ["mem-fs"], rev = "ecde2aa" }
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"main": "dist/Library.cjs.min.js",
"module": "dist/Library.esm.min.js",
"unpkg": "dist/Library.umd.min.js",
"types": "dist/lib.d.ts",
"keywords": [
"webassembly",
"wasm",
Expand All @@ -24,7 +25,7 @@
"access": "public"
},
"scripts": {
"build": "wasm-pack build --release --target web; wasm-opt pkg/wasmer_wasi_js_bg.wasm -O2 -o pkg/wasmer_wasi_js_bg.wasm; wasm-strip pkg/wasmer_wasi_js_bg.wasm; rollup -c --environment BUILD:production",
"build": "wasm-pack build --release --target web && wasm-opt pkg/wasmer_wasi_js_bg.wasm -O2 -o pkg/wasmer_wasi_js_bg.wasm && wasm-strip pkg/wasmer_wasi_js_bg.wasm && rollup -c --environment BUILD:production",
"dev": "rollup -c -w",
"lint": "",
"test": "jest -c jest.config.js",
Expand Down Expand Up @@ -54,7 +55,10 @@
"rollup-plugin-typescript2": "^0.31.0",
"ts-loader": "^9.2.6",
"tslib": "^2.3.1",
"typescript": "^4.5.2"
"typescript": "^4.5.2",
"wabt": "^1.0.30",
"wasm-opt": "^1.3.0",
"wasm-pack": "^0.10.3"
},
"browserslist": "> 0.5%, last 2 versions, Firefox ESR, not dead"
}
23 changes: 21 additions & 2 deletions pkg/wasmer_wasi_js.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
/* tslint:disable */
/* eslint-disable */

interface WasiConfig {
readonly args?: string[],
readonly env?: Record<string, string>,
readonly preopens?: Record<string, string>,
readonly fs?: any,
}


/**
*/
export class JSVirtualFile {
Expand Down Expand Up @@ -56,6 +65,10 @@ export class JSVirtualFile {
export class MemFS {
free(): void;
/**
* @returns {Symbol}
*/
static __wbgd_downcast_token(): Symbol;
/**
*/
constructor();
/**
Expand Down Expand Up @@ -102,9 +115,9 @@ export class MemFS {
export class WASI {
free(): void;
/**
* @param {any} config
* @param {WasiConfig} config
*/
constructor(config: any);
constructor(config: WasiConfig);
/**
* @param {WebAssembly.Module} module
* @returns {object}
Expand Down Expand Up @@ -167,14 +180,20 @@ export class WASI {
*/
export class WasmerRuntimeError {
free(): void;
/**
* @returns {Symbol}
*/
static __wbgd_downcast_token(): Symbol;
}

export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;

export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly __wbg_wasmerruntimeerror_free: (a: number) => void;
readonly wasmerruntimeerror___wbgd_downcast_token: () => number;
readonly __wbg_memfs_free: (a: number) => void;
readonly memfs___wbgd_downcast_token: () => number;
readonly memfs_new: (a: number) => void;
readonly memfs_from_js: (a: number, b: number) => void;
readonly memfs_readDir: (a: number, b: number, c: number, d: number) => void;
Expand Down
Loading

0 comments on commit 89c1e4c

Please sign in to comment.