Skip to content

Truly independent web browser

Tests/LibWeb: Add a test for the WebAssembly struct field limit

Andreas Kling12ad94f03b82
diff --git a/Tests/LibWeb/Text/expected/Wasm/WebAssembly-struct-fields-limit.txt b/Tests/LibWeb/Text/expected/Wasm/WebAssembly-struct-fields-limit.txt
new file mode 100644
index 00000000000..d4a885d830a
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/Wasm/WebAssembly-struct-fields-limit.txt
@@ -0,0 +1,2 @@
+10000 fields: true
+10001 fields: true
diff --git a/Tests/LibWeb/Text/input/Wasm/WebAssembly-struct-fields-limit.html b/Tests/LibWeb/Text/input/Wasm/WebAssembly-struct-fields-limit.html
new file mode 100644
index 00000000000..9406a0549f0
--- /dev/null
+++ b/Tests/LibWeb/Text/input/Wasm/WebAssembly-struct-fields-limit.html
@@ -0,0 +1,35 @@
+<!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 that defines one struct type with `fieldCount` mutable i64 fields.
+ function moduleWithStructFields(fieldCount) {
+ const fields = [];
+ for (let i = 0; i < fieldCount; ++i)
+ fields.push(0x7e, 0x01);
+ return new Uint8Array([
+ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00,
+ ...section(1, [0x01, 0x5f, ...leb(fieldCount), ...fields]),
+ ]);
+ }
+
+ test(() => {
+ println(`10000 fields: ${WebAssembly.validate(moduleWithStructFields(10000))}`);
+ println(`10001 fields: ${WebAssembly.validate(moduleWithStructFields(10001))}`);
+ });
+</script>