throw-ref.js (1411B)
1 wasmFailValidateText(`(module 2 (func 3 throw_ref 4 ) 5 )`, /popping value from empty stack/); 6 7 wasmValidateText(`(module 8 (func (param exnref) 9 local.get 0 10 throw_ref 11 ) 12 )`); 13 14 // Can rethrow a value 15 { 16 let {test} = wasmEvalText(`(module 17 (tag $a) 18 (func (export "test") 19 (block (result (ref exn)) 20 try_table (catch_all_ref 0) 21 throw $a 22 end 23 unreachable 24 ) 25 throw_ref 26 ) 27 )`).exports; 28 29 assertErrorMessage(test, WebAssembly.Exception, /.*/); 30 } 31 32 // Rethrowing a value inside a try works 33 { 34 let {test} = wasmEvalText(`(module 35 (tag $E) 36 (func (export "test") (param $shouldRethrow i32) (result i32) 37 (local $e exnref) 38 (block $catch (result (ref exn)) 39 (try_table (catch_ref $E $catch) (throw $E)) 40 unreachable 41 ) 42 (local.set $e) 43 (block $catch (result (ref exn)) 44 (try_table (result i32) (catch_ref $E $catch) 45 (if (i32.eqz (local.get $shouldRethrow)) 46 (then (throw_ref (local.get $e))) 47 ) 48 (i32.const 2) 49 ) 50 (return) 51 ) 52 (drop) (i32.const 1) 53 ) 54 )`).exports; 55 assertEq(test(0), 1); 56 assertEq(test(1), 2); 57 } 58 59 // Traps on null 60 { 61 let {test} = wasmEvalText(`(module 62 (tag $a) 63 (func (export "test") 64 ref.null exn 65 throw_ref 66 ) 67 )`).exports; 68 69 assertErrorMessage(test, WebAssembly.RuntimeError, /null/); 70 }