Chromium Code Reviews| Index: test/mjsunit/wasm/test-import-export-wrapper.js |
| diff --git a/test/mjsunit/wasm/test-import-export-wrapper.js b/test/mjsunit/wasm/test-import-export-wrapper.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..30349f95ca106d3ce613e386a1315277d6f572f7 |
| --- /dev/null |
| +++ b/test/mjsunit/wasm/test-import-export-wrapper.js |
| @@ -0,0 +1,169 @@ |
| +// Copyright 2016 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Flags: --expose-wasm --allow-natives-syntax |
| + |
| +load("test/mjsunit/wasm/wasm-constants.js"); |
| +load("test/mjsunit/wasm/wasm-module-builder.js"); |
| + |
| +var expect_elison = 0; |
| +var expect_no_elison = 1; |
| +// function calls stack: first_export -> first_func -> first_import -> |
| +// second_export -> second_import |
| +// In this case, first_import and second_export have same signature, |
| +// So that wrappers will be removed |
| +(function TestWasmWrapperElison() { |
| + var second_module = new WasmModuleBuilder(); |
| + var sig_index = second_module.addType(kSig_v_i); |
| + second_module.addImportWithModule("import_module_2", "import_name_2", sig_index); |
| + second_module.addFunction("second_export", sig_index) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprCallImport, kArity1, 0, |
| + ]) |
| + .exportFunc(); |
| + |
| + var first_module = new WasmModuleBuilder(); |
| + var sig_index = first_module.addType(kSig_v_i); |
| + first_module.addImportWithModule("import_module_1", "import_name_1", sig_index); |
| + first_module.addFunction("first_export", sig_index) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprCallFunction, kArity1, 1 |
| + ]) |
| + .exportFunc(); |
| + first_module.addFunction("first_func", sig_index) |
| + .addBody([ |
| + kExprI32Const, 1, |
| + kExprGetLocal, 0, |
| + kExprI32Add, |
| + kExprCallImport, kArity1, 0 |
| + ]); |
| + |
| + var f = second_module.instantiate({import_module_2:{import_name_2:print}}) |
| + .exports.second_export; |
| + var the_export = first_module.instantiate({import_module_1:{import_name_1:f}}) |
|
Mircea Trofin
2016/08/04 00:51:28
don't you want to still call the_export, to make s
Chen
2016/08/04 17:21:53
Done.
|
| + .exports.first_export; |
| + %CheckWasmWrapperElison(the_export, expect_elison); |
| +})(); |
| + |
| +// function calls stack: first_export -> first_func -> first_import -> |
| +// second_export -> second_import |
| +// In this case, second_export has less params than first_import, |
| +// So that wrappers will not be removed |
| +(function TestWasmWrapperNoElisonLessParams() { |
| + var second_module = new WasmModuleBuilder(); |
| + var sig_index_1 = second_module.addType(kSig_v_i); |
| + second_module.addImportWithModule("import_module_2", "import_name_2", sig_index_1); |
| + second_module.addFunction("second_export", sig_index_1) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprCallImport, kArity1, 0 |
| + ]) |
| + .exportFunc(); |
| + |
| + var first_module = new WasmModuleBuilder(); |
| + var sig_index_2 = first_module.addType(kSig_v_ii); |
| + first_module.addImportWithModule("import_module_1", "import_name_1", sig_index_2); |
| + first_module.addFunction("first_export", sig_index_2) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprGetLocal, 1, |
| + kExprCallFunction, kArity2, 1 |
| + ]) |
| + .exportFunc(); |
| + first_module.addFunction("first_func", sig_index_2) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprGetLocal, 1, |
| + kExprCallImport, kArity2, 0 |
| + ]); |
| + |
| + var f = second_module.instantiate({import_module_2:{import_name_2:print}}) |
| + .exports.second_export; |
| + var the_export = first_module.instantiate({import_module_1:{import_name_1:f}}) |
| + .exports.first_export; |
| + %CheckWasmWrapperElison(the_export, expect_no_elison); |
| +})(); |
| + |
| +// function calls stack: first_export -> first_func -> first_import -> |
| +// second_export -> second_import |
| +// In this case, second_export has more params than first_import, |
| +// So that wrappers will not be removed |
| +(function TestWasmWrapperNoElisonMoreParams() { |
| + var second_module = new WasmModuleBuilder(); |
| + var sig_index_3 = second_module.addType(kSig_v_iii); |
| + second_module.addImportWithModule("import_module_2", "import_name_2", sig_index_3); |
| + second_module.addFunction("second_export", sig_index_3) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprGetLocal, 1, |
| + kExprGetLocal, 2, |
| + kExprCallImport, kArity3, 0 |
| + ]) |
| + .exportFunc(); |
| + |
| + var first_module = new WasmModuleBuilder(); |
| + var sig_index_2 = first_module.addType(kSig_v_ii); |
| + first_module.addImportWithModule("import_module_1", "import_name_1", sig_index_2); |
| + first_module.addFunction("first_export", sig_index_2) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprGetLocal, 1, |
| + kExprCallFunction, kArity2, 1 |
| + ]) |
| + .exportFunc(); |
| + first_module.addFunction("first_func", sig_index_2) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprGetLocal, 1, |
| + kExprCallImport, kArity2, 0 |
| + ]); |
| + |
| + var f = second_module.instantiate({import_module_2:{import_name_2:print}}) |
| + .exports.second_export; |
| + var the_export = first_module.instantiate({import_module_1:{import_name_1:f}}) |
| + .exports.first_export; |
| + %CheckWasmWrapperElison(the_export, expect_no_elison); |
| +})(); |
| + |
| +// function calls stack: first_export -> first_func -> first_import -> |
| +// second_export -> second_import |
| +// In this case, second_export has different params type with first_import, |
| +// So that wrappers will not be removed |
| +(function TestWasmWrapperNoElisonTypeMismatch() { |
| + var second_module = new WasmModuleBuilder(); |
| + var sig_index_2 = second_module.addType(kSig_v_dd); |
| + second_module.addImportWithModule("import_module_2", "import_name_2", sig_index_2); |
| + second_module.addFunction("second_export", sig_index_2) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprGetLocal, 1, |
| + kExprCallImport, kArity2, 0 |
| + ]) |
| + .exportFunc(); |
| + |
| + var first_module = new WasmModuleBuilder(); |
| + var sig_index_2 = first_module.addType(kSig_v_ii); |
| + first_module.addImportWithModule("import_module_1", "import_name_1", sig_index_2); |
| + first_module.addFunction("first_export", sig_index_2) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprGetLocal, 1, |
| + kExprCallFunction, kArity2, 1 |
| + ]) |
| + .exportFunc(); |
| + first_module.addFunction("first_func", sig_index_2) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprGetLocal, 1, |
| + kExprCallImport, kArity2, 0 |
| + ]); |
| + |
| + var f = second_module.instantiate({import_module_2:{import_name_2:print}}) |
| + .exports.second_export; |
| + var the_export = first_module.instantiate({import_module_1:{import_name_1:f}}) |
| + .exports.first_export; |
| + %CheckWasmWrapperElison(the_export, expect_no_elison); |
| +})(); |