From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- js/src/jit-test/tests/wasm/multi-value/call-ref.js | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 js/src/jit-test/tests/wasm/multi-value/call-ref.js (limited to 'js/src/jit-test/tests/wasm/multi-value/call-ref.js') diff --git a/js/src/jit-test/tests/wasm/multi-value/call-ref.js b/js/src/jit-test/tests/wasm/multi-value/call-ref.js new file mode 100644 index 0000000000..63b7eb271b --- /dev/null +++ b/js/src/jit-test/tests/wasm/multi-value/call-ref.js @@ -0,0 +1,81 @@ +let counter; +function resetCounter() { counter = 0; } + +function boxNextInt() { return {val: counter++}; } +function unboxInt(box) { return box.val; } +function boxNextThreeInts() { + return [boxNextInt(), boxNextInt(), boxNextInt()]; +} +function unboxThreeInts(x, y, z) { + return [unboxInt(x), unboxInt(y), unboxInt(z)]; +} + +function testAddNextThreeIntsInner(addNextThreeInts) { + resetCounter(); + for (let n = 0; n < 100000; n += 3) { + assertEq(addNextThreeInts(), n * 3 + 3); + } +} + +function testAddNextThreeInts(text, imports) { + let i = new WebAssembly.Instance( + new WebAssembly.Module(wasmTextToBinary(text)), { imports }); + + testAddNextThreeIntsInner(() => i.exports.addNextThreeInts()); +} + +testAddNextThreeInts(` + (module + (func $boxNextInt (import "imports" "boxNextInt") + (result externref)) + (func $unboxInt (import "imports" "unboxInt") + (param externref) (result i32)) + + (func $boxNextThreeInts (result externref externref externref) + call $boxNextInt + call $boxNextInt + call $boxNextInt) + + (func $unboxThreeInts (param externref externref externref) (result i32 i32 i32) + local.get 0 + call $unboxInt + local.get 1 + call $unboxInt + local.get 2 + call $unboxInt) + + (func $addNextThreeInts (export "addNextThreeInts") (result i32) + call $boxNextThreeInts + call $unboxThreeInts + i32.add + i32.add))`, + {boxNextInt, unboxInt}); + +testAddNextThreeInts(` + (module + (func $boxNextThreeInts (import "imports" "boxNextThreeInts") + (result externref externref externref)) + (func $unboxThreeInts (import "imports" "unboxThreeInts") + (param externref externref externref) (result i32 i32 i32)) + + (func $addNextThreeInts (export "addNextThreeInts") (result i32) + call $boxNextThreeInts + call $unboxThreeInts + i32.add + i32.add))`, + {boxNextThreeInts, unboxThreeInts}); + +{ + let i = wasmEvalText(` + (module + (func $boxNextThreeInts (import "imports" "boxNextThreeInts") + (result externref externref externref)) + + (func (export "boxNextThreeInts") (result externref externref externref) + call $boxNextThreeInts))`, + {imports: {boxNextThreeInts}}); + testAddNextThreeIntsInner(() => { + let [a, b, c] = i.exports.boxNextThreeInts(); + return unboxInt(a) + unboxInt(b) + unboxInt(c); + }); +} -- cgit v1.2.3