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; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 var the_export = first_module | 59 var the_export = first_module |
60 .instantiate({import_module_1: {import_name_1: f}}) | 60 .instantiate({import_module_1: {import_name_1: f}}) |
61 .exports.first_export; | 61 .exports.first_export; |
62 assertEquals(the_export(2), 3); | 62 assertEquals(the_export(2), 3); |
63 assertEquals(the_export(-1), 0); | 63 assertEquals(the_export(-1), 0); |
64 assertEquals(the_export(0), 1); | 64 assertEquals(the_export(0), 1); |
65 assertEquals(the_export(5.5), 6); | 65 assertEquals(the_export(5.5), 6); |
66 assertEquals(%CheckWasmWrapperElision(the_export, expect_elison), true); | 66 assertEquals(%CheckWasmWrapperElision(the_export, expect_elison), true); |
67 })(); | 67 })(); |
68 | 68 |
| 69 // Function calls stack: first_export -> first_func -> first_import -> |
| 70 // second_export -> second_import |
| 71 // In this case, first_import and second_export have same signature, |
| 72 // So that wrappers will be removed. If the wrappers do are not removed, then |
| 73 // the test crashes because of the int64 parameter, which is not allowed in the |
| 74 // wrappers. |
| 75 (function TestWasmWrapperElisionInt64() { |
| 76 var imported = function (a) { |
| 77 return a; |
| 78 }; |
| 79 |
| 80 var second_module = new WasmModuleBuilder(); |
| 81 var sig_index1 = second_module.addType(kSig_i_i); |
| 82 var sig_index_ll = second_module.addType(kSig_l_l); |
| 83 second_module |
| 84 .addImportWithModule("import_module_2", "import_name_2", sig_index1); |
| 85 second_module |
| 86 .addFunction("second_export", sig_index_ll) |
| 87 .addBody([ |
| 88 kExprGetLocal, 0, |
| 89 kExprI32ConvertI64, |
| 90 kExprCallFunction, 0, |
| 91 kExprI64SConvertI32, |
| 92 kExprReturn |
| 93 ]) |
| 94 .exportFunc(); |
| 95 |
| 96 var first_module = new WasmModuleBuilder(); |
| 97 var sig_index = first_module.addType(kSig_i_v); |
| 98 var sig_index_ll = first_module.addType(kSig_l_l); |
| 99 first_module |
| 100 .addImportWithModule("import_module_1", "import_name_1", sig_index_ll); |
| 101 first_module |
| 102 .addFunction("first_export", sig_index) |
| 103 .addBody([ |
| 104 kExprI64Const, 2, |
| 105 kExprCallFunction, 2, |
| 106 kExprI32ConvertI64, |
| 107 kExprReturn |
| 108 ]) |
| 109 .exportFunc(); |
| 110 first_module |
| 111 .addFunction("first_func", sig_index_ll) |
| 112 .addBody([ |
| 113 kExprI64Const, 1, |
| 114 kExprGetLocal, 0, |
| 115 kExprI64Add, |
| 116 kExprCallFunction, 0, |
| 117 kExprReturn |
| 118 ]); |
| 119 |
| 120 var f = second_module |
| 121 .instantiate({import_module_2: {import_name_2: imported}}) |
| 122 .exports.second_export; |
| 123 var the_export = first_module |
| 124 .instantiate({import_module_1: {import_name_1: f}}) |
| 125 .exports.first_export; |
| 126 assertEquals(the_export(), 3); |
| 127 })(); |
| 128 |
69 // function calls stack: first_export -> first_func -> first_import -> | 129 // function calls stack: first_export -> first_func -> first_import -> |
70 // second_export -> second_import | 130 // second_export -> second_import |
71 // In this case, second_export has less params than first_import, | 131 // In this case, second_export has less params than first_import, |
72 // So that wrappers will not be removed | 132 // So that wrappers will not be removed |
73 (function TestWasmWrapperNoElisionLessParams() { | 133 (function TestWasmWrapperNoElisionLessParams() { |
74 var imported = function (a) { | 134 var imported = function (a) { |
75 return a; | 135 return a; |
76 }; | 136 }; |
77 | 137 |
78 var second_module = new WasmModuleBuilder(); | 138 var second_module = new WasmModuleBuilder(); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 .exports.second_export; | 292 .exports.second_export; |
233 var the_export = first_module | 293 var the_export = first_module |
234 .instantiate({import_module_1: {import_name_1: f}}) | 294 .instantiate({import_module_1: {import_name_1: f}}) |
235 .exports.first_export; | 295 .exports.first_export; |
236 assertEquals(the_export(2.8, 9.1), 11); | 296 assertEquals(the_export(2.8, 9.1), 11); |
237 assertEquals(the_export(-1.7, -2.5), -3); | 297 assertEquals(the_export(-1.7, -2.5), -3); |
238 assertEquals(the_export(0.0, 0.0), 0); | 298 assertEquals(the_export(0.0, 0.0), 0); |
239 assertEquals(the_export(2, -2), 0); | 299 assertEquals(the_export(2, -2), 0); |
240 assertEquals(%CheckWasmWrapperElision(the_export, expect_no_elison), true); | 300 assertEquals(%CheckWasmWrapperElision(the_export, expect_no_elison), true); |
241 })(); | 301 })(); |
OLD | NEW |