summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/custom-section.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/tests/wasm/custom-section.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/wasm/custom-section.js')
-rw-r--r--js/src/jit-test/tests/wasm/custom-section.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/wasm/custom-section.js b/js/src/jit-test/tests/wasm/custom-section.js
new file mode 100644
index 0000000000..e0a9946242
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/custom-section.js
@@ -0,0 +1,48 @@
+function arraysEqual(a, b) {
+ if (a.length !== b.length) {
+ return false;
+ }
+ for (let i = 0; i < b.length; i++) {
+ if (a[i] !== b[i]) {
+ return false;
+ }
+ }
+ return true;
+}
+
+function testCustomSection(moduleText, customSectionName, expectedBytes) {
+ let module = new WebAssembly.Module(wasmTextToBinary(moduleText));
+
+ let sections = WebAssembly.Module.customSections(module, customSectionName);
+ assertEq(sections.length, 1);
+
+ let section = sections[0];
+ let sectionView = new Uint8Array(section);
+
+ if (!arraysEqual(sectionView, expectedBytes)) {
+ let got = JSON.stringify(Array.from(sectionView));
+ let expected = JSON.stringify(Array.from(expectedBytes));
+ assertEq(true, false, `got: ${got}, expected: ${expected}`)
+ }
+}
+
+// Test an unknown custom section
+testCustomSection(
+ `(module (@custom "unknown" "\\00\\01\\02\\03\\04"))`,
+ "unknown",
+ [0, 1, 2, 3, 4]);
+
+// Test the name section
+testCustomSection(
+ `(module (func $test))`,
+ "name",
+ [
+ /* subsection is functions */ 1,
+ /* subsection is 7 bytes */ 7,
+ /* name map has 1 entry */ 1,
+ /* first entry is index */ 0,
+ /* first entry string 4 bytes */ 4,
+ /* 't' */ 116,
+ /* 'e' */ 101,
+ /* 's' */ 115,
+ /* 't' */ 116]);