summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/lib
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
commitfbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch)
tree4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /js/src/jit-test/lib
parentReleasing progress-linux version 124.0.1-1~progress7.99u1. (diff)
downloadfirefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz
firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/lib')
-rw-r--r--js/src/jit-test/lib/gen/wasm-gc-limits-gen.js71
-rw-r--r--js/src/jit-test/lib/gen/wasm-gc-limits-r1-t1M.wasmbin0 -> 11804 bytes
-rw-r--r--js/src/jit-test/lib/gen/wasm-gc-limits-r1-t1M1.wasmbin0 -> 11804 bytes
-rw-r--r--js/src/jit-test/lib/gen/wasm-gc-limits-r1M-t1.wasmbin0 -> 19647 bytes
-rw-r--r--js/src/jit-test/lib/gen/wasm-gc-limits-r1M1-t1.wasmbin0 -> 19647 bytes
-rw-r--r--js/src/jit-test/lib/gen/wasm-gc-limits-r2-t500K.wasmbin0 -> 11815 bytes
-rw-r--r--js/src/jit-test/lib/gen/wasm-gc-limits-r2-t500K1.wasmbin0 -> 11815 bytes
-rw-r--r--js/src/jit-test/lib/gen/wasm-gc-limits-s10K.wasmbin0 -> 258 bytes
-rw-r--r--js/src/jit-test/lib/gen/wasm-gc-limits-s10K1.wasmbin0 -> 258 bytes
-rw-r--r--js/src/jit-test/lib/prologue.js35
-rw-r--r--js/src/jit-test/lib/wasm-binary.js48
-rw-r--r--js/src/jit-test/lib/wasm.js25
12 files changed, 145 insertions, 34 deletions
diff --git a/js/src/jit-test/lib/gen/wasm-gc-limits-gen.js b/js/src/jit-test/lib/gen/wasm-gc-limits-gen.js
new file mode 100644
index 0000000000..01fd527cc3
--- /dev/null
+++ b/js/src/jit-test/lib/gen/wasm-gc-limits-gen.js
@@ -0,0 +1,71 @@
+// Generates large .wasm files for use in ../limits.js.
+// Make sure you are running this script from a release build or you will be sad.
+
+loadRelativeToScript("../wasm-binary.js");
+
+function moduleNRecGroupNTypes(numRecs, numTypes) {
+ let types = [];
+ for (let i = 0; i < numTypes; i++) {
+ types.push({ kind: FuncCode, args: [], ret: [] });
+ }
+ let recs = [];
+ for (let i = 0; i < numRecs; i++) {
+ recs.push(recGroup(types));
+ }
+ return new Uint8Array(compressLZ4(new Uint8Array(moduleWithSections([typeSection(recs)])).buffer));
+}
+
+os.file.writeTypedArrayToFile("wasm-gc-limits-r1M-t1.wasm", moduleNRecGroupNTypes(1_000_000, 1));
+os.file.writeTypedArrayToFile("wasm-gc-limits-r1M1-t1.wasm", moduleNRecGroupNTypes(1_000_001, 1));
+os.file.writeTypedArrayToFile("wasm-gc-limits-r1-t1M.wasm", moduleNRecGroupNTypes(1, 1_000_000));
+os.file.writeTypedArrayToFile("wasm-gc-limits-r1-t1M1.wasm", moduleNRecGroupNTypes(1, 1_000_001));
+os.file.writeTypedArrayToFile("wasm-gc-limits-r2-t500K.wasm", moduleNRecGroupNTypes(2, 500_000));
+os.file.writeTypedArrayToFile("wasm-gc-limits-r2-t500K1.wasm", moduleNRecGroupNTypes(2, 500_001));
+
+function moduleLargeStruct(size) {
+ let structInitializer = [];
+ for (let i = 0; i < size; i++) {
+ structInitializer.push(I64ConstCode);
+ structInitializer.push(...varU32(0));
+ }
+ return new Uint8Array(compressLZ4(new Uint8Array(moduleWithSections([
+ typeSection([
+ {
+ kind: StructCode,
+ fields: Array(size).fill(I64Code)
+ },
+ {
+ kind: FuncCode,
+ args: [],
+ ret: [AnyRefCode]
+ }
+ ]),
+ declSection([1, 1]),
+ exportSection([
+ {name: "makeLargeStructDefault", funcIndex: 0},
+ {name: "makeLargeStruct", funcIndex: 1}
+ ]),
+ bodySection([
+ funcBody({
+ locals: [],
+ body: [
+ GcPrefix,
+ StructNewDefault,
+ ...varU32(0)
+ ],
+ }),
+ funcBody({
+ locals: [],
+ body: [
+ ...structInitializer,
+ GcPrefix,
+ StructNew,
+ ...varU32(0)
+ ],
+ }),
+ ]),
+ ])).buffer));
+}
+
+os.file.writeTypedArrayToFile("wasm-gc-limits-s10K.wasm", moduleLargeStruct(10_000));
+os.file.writeTypedArrayToFile("wasm-gc-limits-s10K1.wasm", moduleLargeStruct(10_001));
diff --git a/js/src/jit-test/lib/gen/wasm-gc-limits-r1-t1M.wasm b/js/src/jit-test/lib/gen/wasm-gc-limits-r1-t1M.wasm
new file mode 100644
index 0000000000..f92d36f8e3
--- /dev/null
+++ b/js/src/jit-test/lib/gen/wasm-gc-limits-r1-t1M.wasm
Binary files differ
diff --git a/js/src/jit-test/lib/gen/wasm-gc-limits-r1-t1M1.wasm b/js/src/jit-test/lib/gen/wasm-gc-limits-r1-t1M1.wasm
new file mode 100644
index 0000000000..190b522472
--- /dev/null
+++ b/js/src/jit-test/lib/gen/wasm-gc-limits-r1-t1M1.wasm
Binary files differ
diff --git a/js/src/jit-test/lib/gen/wasm-gc-limits-r1M-t1.wasm b/js/src/jit-test/lib/gen/wasm-gc-limits-r1M-t1.wasm
new file mode 100644
index 0000000000..5424e907ff
--- /dev/null
+++ b/js/src/jit-test/lib/gen/wasm-gc-limits-r1M-t1.wasm
Binary files differ
diff --git a/js/src/jit-test/lib/gen/wasm-gc-limits-r1M1-t1.wasm b/js/src/jit-test/lib/gen/wasm-gc-limits-r1M1-t1.wasm
new file mode 100644
index 0000000000..a96be86ef3
--- /dev/null
+++ b/js/src/jit-test/lib/gen/wasm-gc-limits-r1M1-t1.wasm
Binary files differ
diff --git a/js/src/jit-test/lib/gen/wasm-gc-limits-r2-t500K.wasm b/js/src/jit-test/lib/gen/wasm-gc-limits-r2-t500K.wasm
new file mode 100644
index 0000000000..b9eb6ea929
--- /dev/null
+++ b/js/src/jit-test/lib/gen/wasm-gc-limits-r2-t500K.wasm
Binary files differ
diff --git a/js/src/jit-test/lib/gen/wasm-gc-limits-r2-t500K1.wasm b/js/src/jit-test/lib/gen/wasm-gc-limits-r2-t500K1.wasm
new file mode 100644
index 0000000000..e44b6461fe
--- /dev/null
+++ b/js/src/jit-test/lib/gen/wasm-gc-limits-r2-t500K1.wasm
Binary files differ
diff --git a/js/src/jit-test/lib/gen/wasm-gc-limits-s10K.wasm b/js/src/jit-test/lib/gen/wasm-gc-limits-s10K.wasm
new file mode 100644
index 0000000000..5b209ab5e4
--- /dev/null
+++ b/js/src/jit-test/lib/gen/wasm-gc-limits-s10K.wasm
Binary files differ
diff --git a/js/src/jit-test/lib/gen/wasm-gc-limits-s10K1.wasm b/js/src/jit-test/lib/gen/wasm-gc-limits-s10K1.wasm
new file mode 100644
index 0000000000..a2062abc52
--- /dev/null
+++ b/js/src/jit-test/lib/gen/wasm-gc-limits-s10K1.wasm
Binary files differ
diff --git a/js/src/jit-test/lib/prologue.js b/js/src/jit-test/lib/prologue.js
index 4e24b19836..a5c21a5a08 100644
--- a/js/src/jit-test/lib/prologue.js
+++ b/js/src/jit-test/lib/prologue.js
@@ -7,17 +7,32 @@ var appendToActual = function(s) {
actual += s + ',';
}
-// Add dummy versions of missing functions and record whether they
-// were originally present.
+// Add dummy versions of missing functions and record whether they were
+// originally present.
+//
+// This only affects the main global. Any globals created by the test will
+// lack the function.
let hasFunction = {};
-for (const name of ["gczeal",
- "schedulegc",
- "gcslice",
- "selectforgc",
- "verifyprebarriers",
- "verifypostbarriers",
- "gcPreserveCode",
- "setMarkStackLimit"]) {
+for (const name of [
+ // Functions present if JS_GC_ZEAL defined:
+ "gczeal",
+ "unsetgczeal",
+ "schedulegc",
+ "selectforgc",
+ "verifyprebarriers",
+ "verifypostbarriers",
+ "currentgc",
+ "deterministicgc",
+ "dumpGCArenaInfo",
+ "setMarkStackLimit",
+ // Functions present if DEBUG or JS_OOM_BREAKPOINT defined:
+ "oomThreadTypes",
+ "oomAfterAllocations",
+ "oomAtAllocation",
+ "resetOOMFailure",
+ "oomTest",
+ "stackTest",
+ "interruptTest"]) {
const present = name in this;
if (!present) {
this[name] = function() {};
diff --git a/js/src/jit-test/lib/wasm-binary.js b/js/src/jit-test/lib/wasm-binary.js
index c55c8185f5..fdfd2d5732 100644
--- a/js/src/jit-test/lib/wasm-binary.js
+++ b/js/src/jit-test/lib/wasm-binary.js
@@ -44,6 +44,7 @@ const F64Code = 0x7c;
const V128Code = 0x7b;
const AnyFuncCode = 0x70;
const ExternRefCode = 0x6f;
+const AnyRefCode = 0x6e;
const EqRefCode = 0x6d;
const OptRefCode = 0x63; // (ref null $t), needs heap type immediate
const RefCode = 0x64; // (ref $t), needs heap type immediate
@@ -52,6 +53,9 @@ const StructCode = 0x5f;
const ArrayCode = 0x5e;
const VoidCode = 0x40;
const BadType = 0x79; // reserved for testing
+const RecGroupCode = 0x4e;
+const SubFinalTypeCode = 0x4f;
+const SubNoFinalTypeCode = 0x50;
// Opcodes
const UnreachableCode = 0x00
@@ -159,15 +163,17 @@ const MozPrefix = 0xff;
const definedOpcodes =
[0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
- ...(wasmExceptionsEnabled() ? [0x06, 0x07, 0x08, 0x09] : []),
+ 0x06, 0x07, 0x08, 0x09,
+ ...(wasmExnRefEnabled() ? [0x0a] : []),
0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11,
...(wasmTailCallsEnabled() ? [0x12, 0x13] : []),
- ...(wasmFunctionReferencesEnabled() ? [0x14] : []),
+ ...(wasmGcEnabled() ? [0x14] : []),
...(wasmTailCallsEnabled() &&
- wasmFunctionReferencesEnabled() ? [0x15] : []),
- ...(wasmExceptionsEnabled() ? [0x18, 0x19] : []),
+ wasmGcEnabled() ? [0x15] : []),
+ 0x18, 0x19,
0x1a, 0x1b, 0x1c,
+ ...(wasmExnRefEnabled() ? [0x1f] : []),
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
@@ -218,6 +224,7 @@ const ElemDropCode = 0x0d; // Pending
const TableCopyCode = 0x0e; // Pending
const StructNew = 0x00; // UNOFFICIAL
+const StructNewDefault = 0x01; // UNOFFICIAL
const StructGet = 0x03; // UNOFFICIAL
const StructSet = 0x06; // UNOFFICIAL
@@ -232,8 +239,9 @@ const TagCode = 0x04;
const HasMaximumFlag = 0x1;
function toU8(array) {
- for (let b of array)
- assertEq(b < 256, true);
+ for (const [i, b] of array.entries()) {
+ assertEq(b < 256, true, `expected byte at index ${i} but got ${b}`);
+ }
return Uint8Array.from(array);
}
@@ -284,12 +292,14 @@ function encodedString(name, len) {
return varU32(len === undefined ? nameBytes.length : len).concat(nameBytes);
}
-function moduleWithSections(sectionArray) {
- var bytes = moduleHeaderThen();
- for (let section of sectionArray) {
+function moduleWithSections(sections) {
+ const bytes = moduleHeaderThen();
+ for (const section of sections) {
bytes.push(section.name);
bytes.push(...varU32(section.body.length));
- bytes.push(...section.body);
+ for (let byte of section.body) {
+ bytes.push(byte);
+ }
}
return toU8(bytes);
}
@@ -385,13 +395,17 @@ function typeSection(types) {
body.push(...varU32(types.length)); // technically a count of recursion groups
for (const type of types) {
if (type.isRecursionGroup) {
- body.push(0x4f);
+ body.push(RecGroupCode);
body.push(...varU32(type.types.length));
for (const t of type.types) {
- body.push(..._encodeType(t));
+ for (const byte of _encodeType(t)) {
+ body.push(byte);
+ }
}
} else {
- body.push(..._encodeType(type));
+ for (const byte of _encodeType(type)) {
+ body.push(byte);
+ }
}
}
return { name: typeId, body };
@@ -439,12 +453,12 @@ function _encodeType(typeObj) {
// Types are now final by default.
const final = typeObj.final ?? true;
if (typeObj.sub !== undefined) {
- typeBytes.push(final ? 0x4e : 0x50);
+ typeBytes.push(final ? SubFinalTypeCode : SubNoFinalTypeCode);
typeBytes.push(...varU32(1), ...varU32(typeObj.sub));
}
else if (final == false) {
// This type is extensible even if no supertype is defined.
- typeBytes.push(0x50);
+ typeBytes.push(SubNoFinalTypeCode);
typeBytes.push(0x00);
}
typeBytes.push(typeObj.kind);
@@ -514,7 +528,9 @@ function funcBody(func, withEndCode=true) {
var body = varU32(func.locals.length);
for (let local of func.locals)
body.push(...varU32(local));
- body = body.concat(...func.body);
+ for (let byte of func.body) {
+ body.push(byte);
+ }
if (withEndCode)
body.push(EndCode);
body.splice(0, 0, ...varU32(body.length));
diff --git a/js/src/jit-test/lib/wasm.js b/js/src/jit-test/lib/wasm.js
index 2b3374ebbe..a5721913e9 100644
--- a/js/src/jit-test/lib/wasm.js
+++ b/js/src/jit-test/lib/wasm.js
@@ -42,13 +42,12 @@ if (largeArrayBufferSupported()) {
}
var MaxPagesIn32BitMemory = Math.floor(MaxBytesIn32BitMemory / PageSizeInBytes);
-function wasmEvalText(str, imports) {
- let binary = wasmTextToBinary(str);
- let valid = WebAssembly.validate(binary);
+function wasmEvalBinary(binary, imports, compileOptions) {
+ let valid = WebAssembly.validate(binary, compileOptions);
let m;
try {
- m = new WebAssembly.Module(binary);
+ m = new WebAssembly.Module(binary, compileOptions);
assertEq(valid, true, "failed WebAssembly.validate but still compiled successfully");
} catch(e) {
if (!e.toString().match(/out of memory/)) {
@@ -60,8 +59,11 @@ function wasmEvalText(str, imports) {
return new WebAssembly.Instance(m, imports);
}
-function wasmValidateText(str) {
- let binary = wasmTextToBinary(str);
+function wasmEvalText(str, imports, compileOptions) {
+ return wasmEvalBinary(wasmTextToBinary(str), imports, compileOptions);
+}
+
+function wasmValidateBinary(binary) {
let valid = WebAssembly.validate(binary);
if (!valid) {
new WebAssembly.Module(binary);
@@ -70,12 +72,19 @@ function wasmValidateText(str) {
assertEq(valid, true, "wasm module was invalid");
}
-function wasmFailValidateText(str, pattern) {
- let binary = wasmTextToBinary(str);
+function wasmFailValidateBinary(binary, pattern) {
assertEq(WebAssembly.validate(binary), false, "module passed WebAssembly.validate when it should not have");
assertErrorMessage(() => new WebAssembly.Module(binary), WebAssembly.CompileError, pattern, "module failed WebAssembly.validate but did not fail to compile as expected");
}
+function wasmValidateText(str) {
+ return wasmValidateBinary(wasmTextToBinary(str));
+}
+
+function wasmFailValidateText(str, pattern) {
+ return wasmFailValidateBinary(wasmTextToBinary(str), pattern);
+}
+
// Expected compilation failure can happen in a couple of ways:
//
// - The compiler can be available but not capable of recognizing some opcodes: