OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --expose-wasm --allow-natives-syntax | 5 // Flags: --expose-wasm --allow-natives-syntax |
6 | 6 |
7 load("test/mjsunit/wasm/wasm-constants.js"); | 7 load("test/mjsunit/wasm/wasm-constants.js"); |
8 load("test/mjsunit/wasm/wasm-module-builder.js"); | 8 load("test/mjsunit/wasm/wasm-module-builder.js"); |
9 | 9 |
10 var expect_elison = 0; | 10 var expect_elison = 0; |
11 var expect_no_elison = 1; | 11 var expect_no_elison = 1; |
12 // function calls stack: first_export -> first_func -> first_import -> | 12 // function calls stack: first_export -> first_func -> first_import -> |
13 // second_export -> second_import | 13 // second_export -> second_import |
14 // In this case, first_import and second_export have same signature, | 14 // In this case, first_import and second_export have same signature, |
15 // So that wrappers will be removed | 15 // So that wrappers will be removed |
16 (function TestWasmWrapperElision() { | 16 (function TestWasmWrapperElision() { |
17 var imported = function (a) { | 17 var imported = function (a) { |
18 return a; | 18 return a; |
19 }; | 19 }; |
20 | 20 |
21 var second_module = new WasmModuleBuilder(); | 21 var second_module = new WasmModuleBuilder(); |
22 var sig_index = second_module.addType(kSig_i_i); | 22 var sig_index = second_module.addType(kSig_i_i); |
23 second_module | 23 second_module |
24 .addImportWithModule("import_module_2", "import_name_2", sig_index); | 24 .addImport("import_module_2", "import_name_2", sig_index); |
25 second_module | 25 second_module |
26 .addFunction("second_export", sig_index) | 26 .addFunction("second_export", sig_index) |
27 .addBody([ | 27 .addBody([ |
28 kExprGetLocal, 0, | 28 kExprGetLocal, 0, |
29 kExprCallFunction, 0, | 29 kExprCallFunction, 0, |
30 kExprReturn | 30 kExprReturn |
31 ]) | 31 ]) |
32 .exportFunc(); | 32 .exportFunc(); |
33 | 33 |
34 var first_module = new WasmModuleBuilder(); | 34 var first_module = new WasmModuleBuilder(); |
35 var sig_index = first_module.addType(kSig_i_i); | 35 var sig_index = first_module.addType(kSig_i_i); |
36 first_module | 36 first_module |
37 .addImportWithModule("import_module_1", "import_name_1", sig_index); | 37 .addImport("import_module_1", "import_name_1", sig_index); |
38 first_module | 38 first_module |
39 .addFunction("first_export", sig_index) | 39 .addFunction("first_export", sig_index) |
40 .addBody([ | 40 .addBody([ |
41 kExprGetLocal, 0, | 41 kExprGetLocal, 0, |
42 kExprCallFunction, 2, | 42 kExprCallFunction, 2, |
43 kExprReturn | 43 kExprReturn |
44 ]) | 44 ]) |
45 .exportFunc(); | 45 .exportFunc(); |
46 first_module | 46 first_module |
47 .addFunction("first_func", sig_index) | 47 .addFunction("first_func", sig_index) |
(...skipping 26 matching lines...) Expand all Loading... |
74 // wrappers. | 74 // wrappers. |
75 (function TestWasmWrapperElisionInt64() { | 75 (function TestWasmWrapperElisionInt64() { |
76 var imported = function (a) { | 76 var imported = function (a) { |
77 return a; | 77 return a; |
78 }; | 78 }; |
79 | 79 |
80 var second_module = new WasmModuleBuilder(); | 80 var second_module = new WasmModuleBuilder(); |
81 var sig_index1 = second_module.addType(kSig_i_i); | 81 var sig_index1 = second_module.addType(kSig_i_i); |
82 var sig_index_ll = second_module.addType(kSig_l_l); | 82 var sig_index_ll = second_module.addType(kSig_l_l); |
83 second_module | 83 second_module |
84 .addImportWithModule("import_module_2", "import_name_2", sig_index1); | 84 .addImport("import_module_2", "import_name_2", sig_index1); |
85 second_module | 85 second_module |
86 .addFunction("second_export", sig_index_ll) | 86 .addFunction("second_export", sig_index_ll) |
87 .addBody([ | 87 .addBody([ |
88 kExprGetLocal, 0, | 88 kExprGetLocal, 0, |
89 kExprI32ConvertI64, | 89 kExprI32ConvertI64, |
90 kExprCallFunction, 0, | 90 kExprCallFunction, 0, |
91 kExprI64SConvertI32, | 91 kExprI64SConvertI32, |
92 kExprReturn | 92 kExprReturn |
93 ]) | 93 ]) |
94 .exportFunc(); | 94 .exportFunc(); |
95 | 95 |
96 var first_module = new WasmModuleBuilder(); | 96 var first_module = new WasmModuleBuilder(); |
97 var sig_index = first_module.addType(kSig_i_v); | 97 var sig_index = first_module.addType(kSig_i_v); |
98 var sig_index_ll = first_module.addType(kSig_l_l); | 98 var sig_index_ll = first_module.addType(kSig_l_l); |
99 first_module | 99 first_module |
100 .addImportWithModule("import_module_1", "import_name_1", sig_index_ll); | 100 .addImport("import_module_1", "import_name_1", sig_index_ll); |
101 first_module | 101 first_module |
102 .addFunction("first_export", sig_index) | 102 .addFunction("first_export", sig_index) |
103 .addBody([ | 103 .addBody([ |
104 kExprI64Const, 2, | 104 kExprI64Const, 2, |
105 kExprCallFunction, 2, | 105 kExprCallFunction, 2, |
106 kExprI32ConvertI64, | 106 kExprI32ConvertI64, |
107 kExprReturn | 107 kExprReturn |
108 ]) | 108 ]) |
109 .exportFunc(); | 109 .exportFunc(); |
110 first_module | 110 first_module |
(...skipping 20 matching lines...) Expand all Loading... |
131 // In this case, second_export has fewer params than first_import, | 131 // In this case, second_export has fewer params than first_import, |
132 // so instantiation should fail. | 132 // so instantiation should fail. |
133 assertThrows(function TestWasmWrapperNoElisionLessParams() { | 133 assertThrows(function TestWasmWrapperNoElisionLessParams() { |
134 var imported = function (a) { | 134 var imported = function (a) { |
135 return a; | 135 return a; |
136 }; | 136 }; |
137 | 137 |
138 var second_module = new WasmModuleBuilder(); | 138 var second_module = new WasmModuleBuilder(); |
139 var sig_index_1 = second_module.addType(kSig_i_i); | 139 var sig_index_1 = second_module.addType(kSig_i_i); |
140 second_module | 140 second_module |
141 .addImportWithModule("import_module_2", "import_name_2", sig_index_1); | 141 .addImport("import_module_2", "import_name_2", sig_index_1); |
142 second_module | 142 second_module |
143 .addFunction("second_export", sig_index_1) | 143 .addFunction("second_export", sig_index_1) |
144 .addBody([ | 144 .addBody([ |
145 kExprGetLocal, 0, | 145 kExprGetLocal, 0, |
146 kExprCallFunction, 0, | 146 kExprCallFunction, 0, |
147 kExprReturn | 147 kExprReturn |
148 ]) | 148 ]) |
149 .exportFunc(); | 149 .exportFunc(); |
150 | 150 |
151 var first_module = new WasmModuleBuilder(); | 151 var first_module = new WasmModuleBuilder(); |
152 var sig_index_2 = first_module.addType(kSig_i_ii); | 152 var sig_index_2 = first_module.addType(kSig_i_ii); |
153 first_module | 153 first_module |
154 .addImportWithModule("import_module_1", "import_name_1", sig_index_2); | 154 .addImport("import_module_1", "import_name_1", sig_index_2); |
155 first_module | 155 first_module |
156 .addFunction("first_export", sig_index_2) | 156 .addFunction("first_export", sig_index_2) |
157 .addBody([ | 157 .addBody([ |
158 kExprGetLocal, 0, | 158 kExprGetLocal, 0, |
159 kExprGetLocal, 1, | 159 kExprGetLocal, 1, |
160 kExprCallFunction, 2, | 160 kExprCallFunction, 2, |
161 kExprReturn | 161 kExprReturn |
162 ]) | 162 ]) |
163 .exportFunc(); | 163 .exportFunc(); |
164 first_module | 164 first_module |
(...skipping 23 matching lines...) Expand all Loading... |
188 // In this case, second_export has more params than first_import, | 188 // In this case, second_export has more params than first_import, |
189 // so instantiation should fail. | 189 // so instantiation should fail. |
190 assertThrows(function TestWasmWrapperNoElisionMoreParams() { | 190 assertThrows(function TestWasmWrapperNoElisionMoreParams() { |
191 var imported = function (a, b, c) { | 191 var imported = function (a, b, c) { |
192 return a+b+c; | 192 return a+b+c; |
193 }; | 193 }; |
194 | 194 |
195 var second_module = new WasmModuleBuilder(); | 195 var second_module = new WasmModuleBuilder(); |
196 var sig_index_3 = second_module.addType(kSig_i_iii); | 196 var sig_index_3 = second_module.addType(kSig_i_iii); |
197 second_module | 197 second_module |
198 .addImportWithModule("import_module_2", "import_name_2", sig_index_3); | 198 .addImport("import_module_2", "import_name_2", sig_index_3); |
199 second_module | 199 second_module |
200 .addFunction("second_export", sig_index_3) | 200 .addFunction("second_export", sig_index_3) |
201 .addBody([ | 201 .addBody([ |
202 kExprGetLocal, 0, | 202 kExprGetLocal, 0, |
203 kExprGetLocal, 1, | 203 kExprGetLocal, 1, |
204 kExprGetLocal, 2, | 204 kExprGetLocal, 2, |
205 kExprCallFunction, 0, | 205 kExprCallFunction, 0, |
206 kExprReturn | 206 kExprReturn |
207 ]) | 207 ]) |
208 .exportFunc(); | 208 .exportFunc(); |
209 | 209 |
210 var first_module = new WasmModuleBuilder(); | 210 var first_module = new WasmModuleBuilder(); |
211 var sig_index_2 = first_module.addType(kSig_i_ii); | 211 var sig_index_2 = first_module.addType(kSig_i_ii); |
212 first_module | 212 first_module |
213 .addImportWithModule("import_module_1", "import_name_1", sig_index_2); | 213 .addImport("import_module_1", "import_name_1", sig_index_2); |
214 first_module | 214 first_module |
215 .addFunction("first_export", sig_index_2) | 215 .addFunction("first_export", sig_index_2) |
216 .addBody([ | 216 .addBody([ |
217 kExprGetLocal, 0, | 217 kExprGetLocal, 0, |
218 kExprGetLocal, 1, | 218 kExprGetLocal, 1, |
219 kExprCallFunction, 2, | 219 kExprCallFunction, 2, |
220 kExprReturn | 220 kExprReturn |
221 ]) | 221 ]) |
222 .exportFunc(); | 222 .exportFunc(); |
223 first_module | 223 first_module |
(...skipping 23 matching lines...) Expand all Loading... |
247 // In this case, second_export has different params type with first_import, | 247 // In this case, second_export has different params type with first_import, |
248 // so instantiation should fail. | 248 // so instantiation should fail. |
249 assertThrows(function TestWasmWrapperNoElisionTypeMismatch() { | 249 assertThrows(function TestWasmWrapperNoElisionTypeMismatch() { |
250 var imported = function (a, b) { | 250 var imported = function (a, b) { |
251 return a+b; | 251 return a+b; |
252 }; | 252 }; |
253 | 253 |
254 var second_module = new WasmModuleBuilder(); | 254 var second_module = new WasmModuleBuilder(); |
255 var sig_index_2 = second_module.addType(kSig_d_dd); | 255 var sig_index_2 = second_module.addType(kSig_d_dd); |
256 second_module | 256 second_module |
257 .addImportWithModule("import_module_2", "import_name_2", sig_index_2); | 257 .addImport("import_module_2", "import_name_2", sig_index_2); |
258 second_module | 258 second_module |
259 .addFunction("second_export", sig_index_2) | 259 .addFunction("second_export", sig_index_2) |
260 .addBody([ | 260 .addBody([ |
261 kExprGetLocal, 0, | 261 kExprGetLocal, 0, |
262 kExprGetLocal, 1, | 262 kExprGetLocal, 1, |
263 kExprCallFunction, 0, | 263 kExprCallFunction, 0, |
264 kExprReturn | 264 kExprReturn |
265 ]) | 265 ]) |
266 .exportFunc(); | 266 .exportFunc(); |
267 | 267 |
268 var first_module = new WasmModuleBuilder(); | 268 var first_module = new WasmModuleBuilder(); |
269 var sig_index_2 = first_module.addType(kSig_i_ii); | 269 var sig_index_2 = first_module.addType(kSig_i_ii); |
270 first_module | 270 first_module |
271 .addImportWithModule("import_module_1", "import_name_1", sig_index_2); | 271 .addImport("import_module_1", "import_name_1", sig_index_2); |
272 first_module | 272 first_module |
273 .addFunction("first_export", sig_index_2) | 273 .addFunction("first_export", sig_index_2) |
274 .addBody([ | 274 .addBody([ |
275 kExprGetLocal, 0, | 275 kExprGetLocal, 0, |
276 kExprGetLocal, 1, | 276 kExprGetLocal, 1, |
277 kExprCallFunction, 2, | 277 kExprCallFunction, 2, |
278 kExprReturn | 278 kExprReturn |
279 ]) | 279 ]) |
280 .exportFunc(); | 280 .exportFunc(); |
281 first_module | 281 first_module |
(...skipping 10 matching lines...) Expand all Loading... |
292 .exports.second_export; | 292 .exports.second_export; |
293 var the_export = first_module | 293 var the_export = first_module |
294 .instantiate({import_module_1: {import_name_1: f}}) | 294 .instantiate({import_module_1: {import_name_1: f}}) |
295 .exports.first_export; | 295 .exports.first_export; |
296 assertEquals(the_export(2.8, 9.1), 11); | 296 assertEquals(the_export(2.8, 9.1), 11); |
297 assertEquals(the_export(-1.7, -2.5), -3); | 297 assertEquals(the_export(-1.7, -2.5), -3); |
298 assertEquals(the_export(0.0, 0.0), 0); | 298 assertEquals(the_export(0.0, 0.0), 0); |
299 assertEquals(the_export(2, -2), 0); | 299 assertEquals(the_export(2, -2), 0); |
300 assertEquals(%CheckWasmWrapperElision(the_export, expect_no_elison), true); | 300 assertEquals(%CheckWasmWrapperElision(the_export, expect_no_elison), true); |
301 }); | 301 }); |
OLD | NEW |