| 1 |
// |jit-test| skip-if: !WasmHelpers.isSingleStepProfilingEnabled |
| 2 |
|
| 3 |
// Copy of wasm/import-export.js test with WebAssembly.promising |
| 4 |
|
| 5 |
(async function testImportJitExit() { |
| 6 |
let options = getJitCompilerOptions(); |
| 7 |
if (!options['baseline.enable']) |
| 8 |
return; |
| 9 |
|
| 10 |
let baselineTrigger = options['baseline.warmup.trigger']; |
| 11 |
|
| 12 |
let valueToConvert = 0; |
| 13 |
function ffi(n) { if (n == 1337) { return valueToConvert }; return 42; } |
| 14 |
|
| 15 |
function sum(a, b, c) { |
| 16 |
if (a === 1337) |
| 17 |
return valueToConvert; |
| 18 |
return (a|0) + (b|0) + (c|0) | 0; |
| 19 |
} |
| 20 |
|
| 21 |
// Baseline compile ffis. |
| 22 |
for (let i = baselineTrigger + 1; i --> 0;) { |
| 23 |
ffi(i); |
| 24 |
sum((i%2)?i:undefined, |
| 25 |
(i%3)?i:undefined, |
| 26 |
(i%4)?i:undefined); |
| 27 |
} |
| 28 |
|
| 29 |
let imports = { |
| 30 |
a: { |
| 31 |
ffi, |
| 32 |
sum |
| 33 |
} |
| 34 |
}; |
| 35 |
|
| 36 |
i = wasmEvalText(`(module |
| 37 |
(import "a" "ffi" (func $ffi (param i32) (result i32))) |
| 38 |
|
| 39 |
(import "a" "sum" (func $missingOneArg (param i32) (param i32) (result i32))) |
| 40 |
(import "a" "sum" (func $missingTwoArgs (param i32) (result i32))) |
| 41 |
(import "a" "sum" (func $missingThreeArgs (result i32))) |
| 42 |
|
| 43 |
(func (export "foo") (param i32) (result i32) |
| 44 |
local.get 0 |
| 45 |
call $ffi |
| 46 |
) |
| 47 |
|
| 48 |
(func (export "missThree") (result i32) |
| 49 |
call $missingThreeArgs |
| 50 |
) |
| 51 |
|
| 52 |
(func (export "missTwo") (param i32) (result i32) |
| 53 |
local.get 0 |
| 54 |
call $missingTwoArgs |
| 55 |
) |
| 56 |
|
| 57 |
(func (export "missOne") (param i32) (param i32) (result i32) |
| 58 |
local.get 0 |
| 59 |
local.get 1 |
| 60 |
call $missingOneArg |
| 61 |
) |
| 62 |
)`, imports).exports; |
| 63 |
|
| 64 |
// Enable the jit exit for each JS callee. |
| 65 |
assertEq(i.foo(0), 42); |
| 66 |
|
| 67 |
assertEq(i.missThree(), 0); |
| 68 |
assertEq(i.missTwo(42), 42); |
| 69 |
assertEq(i.missOne(13, 37), 50); |
| 70 |
|
| 71 |
// Test the jit exit under normal conditions. |
| 72 |
assertEq(i.foo(0), 42); |
| 73 |
assertEq(i.foo(1337), 0); |
| 74 |
|
| 75 |
enableGeckoProfiling(); |
| 76 |
enableSingleStepProfiling(); |
| 77 |
|
| 78 |
// Test on suspendable stack. |
| 79 |
var f = WebAssembly.promising(i.foo); |
| 80 |
assertEq(await f(0), 42); |
| 81 |
|
| 82 |
const stacks = disableSingleStepProfiling(); |
| 83 |
WasmHelpers.assertEqImpreciseStacks(stacks, |
| 84 |
["", ">", "1,>", "<,1,>", "CreateSuspender,1,>", "<,1,>", "1,>", "<,1,>", |
| 85 |
"CreatePromisingPromise,1,>", "<,1,>", "1,>", "<,1,>", "#ref.func function,1,>", |
| 86 |
"<,1,>", "1,>", "<,1,>", "#update suspender state util,1,>", "<,1,>", "1,>", |
| 87 |
"2,1,>", "4,2,1,>", "<,4,2,1,>", "4,2,1,>", "2,1,>", "<,2,1,>", |
| 88 |
"SetPromisingPromiseResults,2,1,>", "<,2,1,>", "2,1,>", "1,>", "<,1,>", |
| 89 |
"#update suspender state util,1,>", "<,1,>", "1,>", ">", ""] |
| 90 |
); |
| 91 |
|
| 92 |
disableGeckoProfiling(); |
| 93 |
|
| 94 |
// Test the arguments rectifier. |
| 95 |
assertEq(i.missThree(), 0); |
| 96 |
assertEq(i.missTwo(-1), -1); |
| 97 |
assertEq(i.missOne(23, 10), 33); |
| 98 |
|
| 99 |
// Test OOL coercion. |
| 100 |
valueToConvert = 2**31; |
| 101 |
assertEq(i.foo(1337), -(2**31)); |
| 102 |
|
| 103 |
// Test OOL error path. |
| 104 |
valueToConvert = { valueOf() { throw new Error('make ffi great again'); } } |
| 105 |
assertErrorMessage(() => i.foo(1337), Error, "make ffi great again"); |
| 106 |
|
| 107 |
valueToConvert = { toString() { throw new Error('a FFI to believe in'); } } |
| 108 |
assertErrorMessage(() => i.foo(1337), Error, "a FFI to believe in"); |
| 109 |
|
| 110 |
// Test the error path in the arguments rectifier. |
| 111 |
assertErrorMessage(() => i.missTwo(1337), Error, "a FFI to believe in"); |
| 112 |
})(); |