Debian Codegraph @

js/src/jit-test/tests/wasm/exceptions/import-export.js

raw
1 // Tests for Wasm exception import and export.
2
3 function testImports() {
4 var mod = `
5 (module
6 (type (func (param i32 i32)))
7 (import "m" "exn" (tag (type 0))))
8 `;
9
10 assertErrorMessage(
11 () => wasmEvalText(mod, { m: { exn: "not a tag" } }),
12 WebAssembly.LinkError,
13 /import object field 'exn' is not a Tag/
14 );
15 }
16
17 function testExports() {
18 var exports1 = wasmEvalText(`
19 (module (type (func)) (tag (export "exn") (type 0)))
20 `).exports;
21
22 assertEq(typeof exports1.exn, "object");
23 assertEq(exports1.exn instanceof WebAssembly.Tag, true);
24
25 var exports2 = wasmEvalText(`
26 (module
27 (type (func (param i32 i32)))
28 (tag (export "exn") (type 0)))
29 `).exports;
30
31 assertEq(typeof exports2.exn, "object");
32 assertEq(exports2.exn instanceof WebAssembly.Tag, true);
33 }
34
35 function testImportExport() {
36 var exports = wasmEvalText(`
37 (module
38 (type (func (param i32)))
39 (tag (export "exn") (type 0)))
40 `).exports;
41
42 wasmEvalText(
43 `
44 (module
45 (type (func (param i32)))
46 (import "m" "exn" (tag (type 0))))
47 `,
48 { m: exports }
49 );
50
51 assertErrorMessage(
52 () => {
53 wasmEvalText(
54 `
55 (module
56 (type (func (param)))
57 (import "m" "exn" (tag (type 0))))
58 `,
59 { m: exports }
60 );
61 },
62 WebAssembly.LinkError,
63 /imported tag 'm.exn' signature mismatch/
64 );
65 }
66
67 function testImportExportRecGroup() {
68 const a = wasmEvalText(`(module
69 (type $t1 (func (param i32)))
70 (tag (export "tag") (type $t1))
71 )`);
72 assertErrorMessage(() => {
73 wasmEvalText(`(module
74 (rec
75 (type $t1 (func (param i32)))
76 (type $t2 (func (param i32)))
77 )
78 (tag (import "a" "tag") (type $t2))
79 )`, { a: a.exports });
80 }, WebAssembly.LinkError, /signature mismatch/);
81 }
82
83 // Test imports/exports descriptions.
84 function testDescriptions() {
85 const imports = WebAssembly.Module.imports(
86 new WebAssembly.Module(
87 wasmTextToBinary(`
88 (module $m
89 (type (func))
90 (import "m" "e" (tag (type 0))))
91 `)
92 )
93 );
94
95 const exports = WebAssembly.Module.exports(
96 new WebAssembly.Module(
97 wasmTextToBinary(`
98 (module
99 (type (func))
100 (tag (export "e") (type 0)))
101 `)
102 )
103 );
104
105 assertEq(imports[0].module, "m");
106 assertEq(imports[0].name, "e");
107 assertEq(imports[0].kind, "tag");
108
109 assertEq(exports[0].name, "e");
110 assertEq(exports[0].kind, "tag");
111 }
112
113 testImports();
114 testExports();
115 testImportExport();
116 testImportExportRecGroup();
117 testDescriptions();