| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 .instantiate({import_module_2: {import_name_2: imported}}) | 121 .instantiate({import_module_2: {import_name_2: imported}}) |
| 122 .exports.second_export; | 122 .exports.second_export; |
| 123 var the_export = first_module | 123 var the_export = first_module |
| 124 .instantiate({import_module_1: {import_name_1: f}}) | 124 .instantiate({import_module_1: {import_name_1: f}}) |
| 125 .exports.first_export; | 125 .exports.first_export; |
| 126 assertEquals(the_export(), 3); | 126 assertEquals(the_export(), 3); |
| 127 })(); | 127 })(); |
| 128 | 128 |
| 129 // function calls stack: first_export -> first_func -> first_import -> | 129 // function calls stack: first_export -> first_func -> first_import -> |
| 130 // second_export -> second_import | 130 // second_export -> second_import |
| 131 // In this case, second_export has less params than first_import, | 131 // In this case, second_export has fewer params than first_import, |
| 132 // So that wrappers will not be removed | 132 // so instantiation should fail. |
| 133 (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 .addImportWithModule("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) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 174 .instantiate({import_module_2: {import_name_2: imported}}) | 174 .instantiate({import_module_2: {import_name_2: imported}}) |
| 175 .exports.second_export; | 175 .exports.second_export; |
| 176 var the_export = first_module | 176 var the_export = first_module |
| 177 .instantiate({import_module_1: {import_name_1: f}}) | 177 .instantiate({import_module_1: {import_name_1: f}}) |
| 178 .exports.first_export; | 178 .exports.first_export; |
| 179 assertEquals(the_export(4, 5), 4); | 179 assertEquals(the_export(4, 5), 4); |
| 180 assertEquals(the_export(-1, 4), -1); | 180 assertEquals(the_export(-1, 4), -1); |
| 181 assertEquals(the_export(0, 2), 0); | 181 assertEquals(the_export(0, 2), 0); |
| 182 assertEquals(the_export(9.9, 4.3), 9); | 182 assertEquals(the_export(9.9, 4.3), 9); |
| 183 assertEquals(%CheckWasmWrapperElision(the_export, expect_no_elison), true); | 183 assertEquals(%CheckWasmWrapperElision(the_export, expect_no_elison), true); |
| 184 })(); | 184 }); |
| 185 | 185 |
| 186 // function calls stack: first_export -> first_func -> first_import -> | 186 // function calls stack: first_export -> first_func -> first_import -> |
| 187 // second_export -> second_import | 187 // second_export -> second_import |
| 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 that wrappers will not be removed | 189 // so instantiation should fail. |
| 190 (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 .addImportWithModule("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) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 .instantiate({import_module_2: {import_name_2: imported}}) | 233 .instantiate({import_module_2: {import_name_2: imported}}) |
| 234 .exports.second_export; | 234 .exports.second_export; |
| 235 var the_export = first_module | 235 var the_export = first_module |
| 236 .instantiate({import_module_1: {import_name_1: f}}) | 236 .instantiate({import_module_1: {import_name_1: f}}) |
| 237 .exports.first_export; | 237 .exports.first_export; |
| 238 assertEquals(the_export(5, 6), 11); | 238 assertEquals(the_export(5, 6), 11); |
| 239 assertEquals(the_export(-1, -4), -5); | 239 assertEquals(the_export(-1, -4), -5); |
| 240 assertEquals(the_export(0, 0), 0); | 240 assertEquals(the_export(0, 0), 0); |
| 241 assertEquals(the_export(1.1, 2.7), 3); | 241 assertEquals(the_export(1.1, 2.7), 3); |
| 242 assertEquals(%CheckWasmWrapperElision(the_export, expect_no_elison), true); | 242 assertEquals(%CheckWasmWrapperElision(the_export, expect_no_elison), true); |
| 243 })(); | 243 }); |
| 244 | 244 |
| 245 // function calls stack: first_export -> first_func -> first_import -> | 245 // function calls stack: first_export -> first_func -> first_import -> |
| 246 // second_export -> second_import | 246 // second_export -> second_import |
| 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 that wrappers will not be removed | 248 // so instantiation should fail. |
| 249 (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 .addImportWithModule("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) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 .instantiate({import_module_2: {import_name_2: imported}}) | 291 .instantiate({import_module_2: {import_name_2: imported}}) |
| 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 |