Truly independent web browser
Tests/LibWeb: Add a test for the WebAssembly locals limit
Andreas Klingab29743cf458
diff --git a/Tests/LibWeb/Text/expected/Wasm/WebAssembly-locals-limit.txt b/Tests/LibWeb/Text/expected/Wasm/WebAssembly-locals-limit.txtnew file mode 100644index 00000000000..717422f970a--- /dev/null+++ b/Tests/LibWeb/Text/expected/Wasm/WebAssembly-locals-limit.txt@@ -0,0 +1,4 @@+50000 locals with the parameters: false+50001 locals with the parameters: false+50001 locals without parameters: true+84138 locals in two runs: truediff --git a/Tests/LibWeb/Text/input/Wasm/WebAssembly-locals-limit.html b/Tests/LibWeb/Text/input/Wasm/WebAssembly-locals-limit.htmlnew file mode 100644index 00000000000..d99a63090f7--- /dev/null+++ b/Tests/LibWeb/Text/input/Wasm/WebAssembly-locals-limit.html@@ -0,0 +1,42 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ function leb(value) {+ const bytes = [];+ do {+ let byte = value % 128;+ value = Math.floor(value / 128);+ if (value !== 0)+ byte |= 0x80;+ bytes.push(byte);+ } while (value !== 0);+ return bytes;+ }++ function section(id, contents) {+ return [id, ...leb(contents.length), ...contents];+ }++ // A module with one function that has `parameterCount` i32 parameters and declares a run of i32 locals for+ // each count in `runs`.+ function moduleWithLocals(parameterCount, runs) {+ const types = [0x01, 0x60, ...leb(parameterCount), ...new Array(parameterCount).fill(0x7f), 0x00];+ const body = [...leb(runs.length)];+ for (const count of runs)+ body.push(...leb(count), 0x7f);+ body.push(0x0b);+ return new Uint8Array([+ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00,+ ...section(1, types),+ ...section(3, [0x01, 0x00]),+ ...section(10, [0x01, ...leb(body.length), ...body]),+ ]);+ }++ test(() => {+ println(`50000 locals with the parameters: ${WebAssembly.validate(moduleWithLocals(1, [49999]))}`);+ println(`50001 locals with the parameters: ${WebAssembly.validate(moduleWithLocals(1, [50000]))}`);+ println(`50001 locals without parameters: ${WebAssembly.validate(moduleWithLocals(0, [25000, 25001]))}`);+ println(`84138 locals in two runs: ${WebAssembly.validate(moduleWithLocals(0, [42069, 42069]))}`);+ });+</script>