example.js (966B)
1 // A diagram depicting the control flow graph of the function g below can be 2 // found in "js/src/wasm/WasmIonCompile.cpp". If you make any changes to this 3 // test file be sure to adjust the SMDOC documentation there as well. 4 5 let g = wasmEvalText( 6 `(module 7 (tag $exn (param f64)) 8 (func $f) 9 (func (export "g") (param $arg i32) (result f64) 10 (local.get $arg) 11 try (param i32) (result f64) 12 (if (result f64) 13 (then 14 (f64.const 3)) 15 (else 16 (throw $exn (f64.const 6)))) 17 (call $f) 18 (f64.sub (f64.const 2)) ;; If $arg is 0 we end here, subtracting 3. 19 ;; If $arg is not 0 then the else-block throws $exn, caught below. 20 catch $exn 21 (f64.add (f64.const 4)) ;; Adds 4 to the value in the $exn (6). 22 catch_all ;; This shouldn't occur. 23 (f64.const 5) 24 end 25 ))` 26 ).exports.g; 27 28 assertEq(g(0), 10); 29 assertEq(g(1), 1);