@@ -69,6 +69,11 @@ export class GBZBaseAPI extends APIInterface {
69
69
70
70
// Make a call into the WebAssembly code and return the result.
71
71
async callWasm ( argv ) {
72
+ if ( argv . length < 1 ) {
73
+ // We need at least one command line argument to be the program name.
74
+ throw new Error ( "Not safe to invoke main() without program name" ) ;
75
+ }
76
+
72
77
await this . setUp ( ) ;
73
78
let wasm = this . compiledWasm ;
74
79
@@ -78,7 +83,7 @@ export class GBZBaseAPI extends APIInterface {
78
83
let stderr = new File ( [ ] ) ;
79
84
80
85
// Environment variables as NAME=value strings
81
- const environment = [ ] ;
86
+ const environment = [ "RUST_BACKTRACE=full" ] ;
82
87
83
88
// File descriptors for the process in number order
84
89
let file_descriptors = [ new OpenFile ( stdin ) , new OpenFile ( stdout ) , new OpenFile ( stderr ) ] ;
@@ -91,12 +96,15 @@ export class GBZBaseAPI extends APIInterface {
91
96
"wasi_snapshot_preview1" : wasi . wasiImport ,
92
97
} ) ;
93
98
94
- // Make the WASI system call main
95
- let returnCode = wasi . start ( instantiation ) ;
96
-
97
- console . log ( "Return code:" , returnCode ) ;
98
- console . log ( "Standard Output:" , stdout ) ;
99
- console . log ( "Standard Error:" , stderr ) ;
99
+ try {
100
+ // Make the WASI system call main
101
+ let returnCode = wasi . start ( instantiation ) ;
102
+ console . log ( "Return code:" , returnCode ) ;
103
+ } finally {
104
+ // The WASM code can throw right out of the WASI shim if Rust panics.
105
+ console . log ( "Standard Output:" , new TextDecoder ( ) . decode ( stdout . data ) ) ;
106
+ console . log ( "Standard Error:" , new TextDecoder ( ) . decode ( stderr . data ) ) ;
107
+ }
100
108
}
101
109
102
110
/////////
0 commit comments