ion-inlinedcall-resumepoint.js (1195B)
1 var invalidatedFunction = function() { return false; } 2 3 var counter = 0; 4 5 function maybeInvalidate(iplusk) { 6 if (iplusk === 0) { 7 // This should happen only once; it will invalidate the call frame of 8 // the ion() function, which should rewind to just after the wasm call 9 // (if it got its own resume point). 10 // Before the patch, the wasm call doesn't get its resume point, so 11 // it's repeated and the importedFunc() is called once too many. 12 counter++; 13 invalidatedFunction = function () { return true; }; 14 } 15 } 16 17 function importedFunc(k) { 18 for (let i = 100; i --> 0 ;) { 19 maybeInvalidate(i + k); 20 } 21 } 22 23 let { exports } = new WebAssembly.Instance( 24 new WebAssembly.Module( 25 wasmTextToBinary(` 26 (module 27 (func $imp (import "env" "importedFunc") (param i32)) 28 (func (export "exp") (param i32) 29 local.get 0 30 call $imp 31 ) 32 ) 33 `) 34 ), { 35 env: { 36 importedFunc 37 } 38 } 39 ); 40 41 function ion(k) { 42 exports.exp(k); 43 invalidatedFunction(); 44 } 45 46 for (let k = 100; k --> 0 ;) { 47 ion(k); 48 } 49 50 assertEq(counter, 1);