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..698a46802f920ccea291e90858a0efaf8304c142 |
| --- /dev/null |
| +++ b/test/mjsunit/wasm/test-import-export-wrapper.js |
| @@ -0,0 +1,154 @@ |
| +// 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"); |
| + |
| +(function TestImportExportNoWrapper() { |
| + var second_module = new WasmModuleBuilder(); |
| + var sig_index = second_module.addType(kSig_v_i); |
| + second_module.addImportWithModule("js", "thePrint", sig_index); |
|
Mircea Trofin
2016/08/03 22:52:16
can you change the names, instead of "thePrint" an
|
| + 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("blah", "nothing", sig_index); |
| + first_module.addFunction("export_fct", sig_index) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprCallFunction, kArity1, 1 |
| + ]) |
| + .exportFunc(); |
| + first_module.addFunction("increment", sig_index) |
| + .addBody([ |
| + kExprI32Const, 1, |
| + kExprGetLocal, 0, |
| + kExprI32Add, |
| + kExprCallImport, kArity1, 0 |
| + ]); |
| + |
| + var f = second_module.instantiate({js:{thePrint:print}}).exports.second_export; |
|
Mircea Trofin
2016/08/03 22:52:16
80 char limit - git cl format, unfortunately, does
|
| + var the_export = first_module.instantiate({blah:{nothing:f}}).exports.export_fct; |
| + |
| + the_export(2); |
|
Mircea Trofin
2016/08/03 22:52:16
want to check the result?
|
| + %CheckImportExportFunction(the_export, 0); |
|
Mircea Trofin
2016/08/03 22:52:16
maybe add somewhere a var expect_no_elision = 1 an
|
| + |
| +})(); |
| + |
| +(function TestImportExportWrapperLessParams() { |
| + var second_module = new WasmModuleBuilder(); |
| + var sig_index_1 = second_module.addType(kSig_v_i); |
| + second_module.addImportWithModule("js", "thePrint", 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("blah", "nothing", sig_index_2); |
| + first_module.addFunction("export_fct", sig_index_2) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprGetLocal, 1, |
| + kExprCallFunction, kArity2, 1 |
| + ]) |
| + .exportFunc(); |
| + first_module.addFunction("increment", sig_index_2) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprGetLocal, 1, |
| + kExprCallImport, kArity2, 0 |
| + ]); |
| + |
| + var f = second_module.instantiate({js:{thePrint:print}}).exports.second_export; |
| + var the_export = first_module.instantiate({blah:{nothing:f}}).exports.export_fct; |
| + |
| + the_export(4, 3); |
|
Mircea Trofin
2016/08/03 22:52:16
check result? (same for the remainder)
should the
|
| + %CheckImportExportFunction(the_export, 1); |
| + |
| +})(); |
| + |
| +(function TestImportExportWrapperMoreParams() { |
| + var second_module = new WasmModuleBuilder(); |
| + var sig_index_3 = second_module.addType(kSig_v_iii); |
| + second_module.addImportWithModule("js", "thePrint", 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("blah", "nothing", sig_index_2); |
| + first_module.addFunction("export_fct", sig_index_2) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprGetLocal, 1, |
| + kExprCallFunction, kArity2, 1 |
| + ]) |
| + .exportFunc(); |
| + first_module.addFunction("increment", sig_index_2) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprGetLocal, 1, |
| + kExprCallImport, kArity2, 0 |
| + ]); |
| + |
| + var f = second_module.instantiate({js:{thePrint:print}}).exports.second_export; |
| + var the_export = first_module.instantiate({blah:{nothing:f}}).exports.export_fct; |
| + |
| + the_export(5, 4); |
| + %CheckImportExportFunction(the_export, 1); |
| + |
| +})(); |
| + |
| +(function TestImportExportWrapperTypeMismatch() { |
| + var second_module = new WasmModuleBuilder(); |
| + var sig_index_2 = second_module.addType(kSig_v_dd); |
| + second_module.addImportWithModule("js", "thePrint", 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("blah", "nothing", sig_index_2); |
| + first_module.addFunction("export_fct", sig_index_2) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprGetLocal, 1, |
| + kExprCallFunction, kArity2, 1 |
| + ]) |
| + .exportFunc(); |
| + first_module.addFunction("increment", sig_index_2) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprGetLocal, 1, |
| + kExprCallImport, kArity2, 0 |
| + ]); |
| + |
| + var f = second_module.instantiate({js:{thePrint:print}}).exports.second_export; |
| + var the_export = first_module.instantiate({blah:{nothing:f}}).exports.export_fct; |
| + |
| + the_export(6, 8); |
| + %CheckImportExportFunction(the_export, 1); |
| +})(); |