timeout.js (993B)
1 // Test if user code in interrupt handler causes the problem. 2 3 // Stay in wasm for long time (double loop) so timeout can be triggerred. 4 var ins = wasmEvalText(`(module 5 (global $g (mut i32) (i32.const 0)) 6 7 (func $f0 (param i32) (result i64) 8 (local $s i64) 9 loop 10 local.get $s 11 global.get $g 12 br_if 1 13 14 i64.const 1 15 i64.add 16 local.set $s 17 local.get 0 18 i32.const 1 19 i32.sub 20 local.tee 0 21 br_if 0 22 end 23 local.get $s 24 ) 25 26 (func (export "f") (param i32) 27 (local $i i32) 28 local.get 0 29 local.set $i 30 loop 31 global.get $g 32 br_if 1 33 34 local.get 0 35 call $f0 36 drop 37 local.get $i 38 i32.const 1 39 i32.sub 40 local.tee $i 41 br_if 0 42 end 43 ) 44 45 (func (export "stop") 46 i32.const 1 47 global.set $g 48 ) 49 )`); 50 51 var promising = WebAssembly.promising(ins.exports.f); 52 53 timeout(0.1, function() { 54 print("timeout!"); 55 ins.exports.stop(); 56 return true; 57 }); 58 59 promising(200000);