File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7878
7979 * ** readDebugNames** : ` boolean ` <br />
8080 Reads textual names from the name section.
81+ * ** check** : ` boolean ` <br />
82+ Check for invalid modules (default: true).
8183
8284* ** ToTextOptions** <br />
8385 Options modifying the behavior of ` WasmModule#toText ` .
Original file line number Diff line number Diff line change @@ -40,6 +40,9 @@ interface WasmFeatures { // see: https://github.com/WebAssembly/wabt/blob/main/s
4040interface ReadWasmOptions {
4141 /** Reads textual names from the name section. */
4242 readDebugNames ?: boolean ;
43+
44+ /** Check for invalid modules (default is true). */
45+ check ?: boolean ;
4346}
4447
4548/** Options modifying the behavior of `WasmModule#toText`. */
Original file line number Diff line number Diff line change @@ -31,6 +31,24 @@ require("..")().then(wabt => {
3131 test . end ( ) ;
3232 } ) ;
3333
34+ test ( "loading an invalid binary module" , function ( test ) {
35+ var buffer = new Uint8Array (
36+ fs . readFileSync ( __dirname + "/assembly/module-features.wasm" )
37+ ) ;
38+ buffer [ buffer . length - 1 ] = 0x00 ; // corrupt the last byte
39+ test . throws ( function ( ) {
40+ mod = wabt . readWasm ( buffer , { } ) ;
41+ } , / f u n c t i o n b o d y m u s t e n d w i t h E N D o p c o d e / ) ;
42+ // Specifying `check: true` allows an invalid module to be loaded.
43+ test . doesNotThrow ( function ( ) {
44+ mod = wabt . readWasm ( buffer , {
45+ check : false
46+ } ) ;
47+ } ) ;
48+ test . ok ( mod && typeof mod . toBinary === "function" , "should return a module" ) ;
49+ test . end ( ) ;
50+ } ) ;
51+
3452 test ( "modifying a module" , function ( test ) {
3553 test . doesNotThrow ( function ( ) {
3654 mod . generateNames ( ) ;
You can’t perform that action at this time.
0 commit comments