OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // Flags: --expose-wasm --allow-natives-syntax | |
6 | |
7 load("test/mjsunit/wasm/wasm-constants.js"); | |
8 load("test/mjsunit/wasm/wasm-module-builder.js"); | |
9 | |
10 (function TestImportExportNoWrapper() { | |
11 var second_module = new WasmModuleBuilder(); | |
12 var sig_index = second_module.addType(kSig_v_i); | |
13 second_module.addImportWithModule("js", "thePrint", sig_index); | |
Mircea Trofin
2016/08/03 22:52:16
can you change the names, instead of "thePrint" an
| |
14 second_module.addFunction("second_export", sig_index) | |
15 .addBody([ | |
16 kExprGetLocal, 0, | |
17 kExprCallImport, kArity1, 0 | |
18 ]) | |
19 .exportFunc(); | |
20 | |
21 var first_module = new WasmModuleBuilder(); | |
22 var sig_index = first_module.addType(kSig_v_i); | |
23 first_module.addImportWithModule("blah", "nothing", sig_index); | |
24 first_module.addFunction("export_fct", sig_index) | |
25 .addBody([ | |
26 kExprGetLocal, 0, | |
27 kExprCallFunction, kArity1, 1 | |
28 ]) | |
29 .exportFunc(); | |
30 first_module.addFunction("increment", sig_index) | |
31 .addBody([ | |
32 kExprI32Const, 1, | |
33 kExprGetLocal, 0, | |
34 kExprI32Add, | |
35 kExprCallImport, kArity1, 0 | |
36 ]); | |
37 | |
38 var f = second_module.instantiate({js:{thePrint:print}}).exports.second_expo rt; | |
Mircea Trofin
2016/08/03 22:52:16
80 char limit - git cl format, unfortunately, does
| |
39 var the_export = first_module.instantiate({blah:{nothing:f}}).exports.export _fct; | |
40 | |
41 the_export(2); | |
Mircea Trofin
2016/08/03 22:52:16
want to check the result?
| |
42 %CheckImportExportFunction(the_export, 0); | |
Mircea Trofin
2016/08/03 22:52:16
maybe add somewhere a var expect_no_elision = 1 an
| |
43 | |
44 })(); | |
45 | |
46 (function TestImportExportWrapperLessParams() { | |
47 var second_module = new WasmModuleBuilder(); | |
48 var sig_index_1 = second_module.addType(kSig_v_i); | |
49 second_module.addImportWithModule("js", "thePrint", sig_index_1); | |
50 second_module.addFunction("second_export", sig_index_1) | |
51 .addBody([ | |
52 kExprGetLocal, 0, | |
53 kExprCallImport, kArity1, 0 | |
54 ]) | |
55 .exportFunc(); | |
56 | |
57 var first_module = new WasmModuleBuilder(); | |
58 var sig_index_2 = first_module.addType(kSig_v_ii); | |
59 first_module.addImportWithModule("blah", "nothing", sig_index_2); | |
60 first_module.addFunction("export_fct", sig_index_2) | |
61 .addBody([ | |
62 kExprGetLocal, 0, | |
63 kExprGetLocal, 1, | |
64 kExprCallFunction, kArity2, 1 | |
65 ]) | |
66 .exportFunc(); | |
67 first_module.addFunction("increment", sig_index_2) | |
68 .addBody([ | |
69 kExprGetLocal, 0, | |
70 kExprGetLocal, 1, | |
71 kExprCallImport, kArity2, 0 | |
72 ]); | |
73 | |
74 var f = second_module.instantiate({js:{thePrint:print}}).exports.second_expo rt; | |
75 var the_export = first_module.instantiate({blah:{nothing:f}}).exports.export _fct; | |
76 | |
77 the_export(4, 3); | |
Mircea Trofin
2016/08/03 22:52:16
check result? (same for the remainder)
should the
| |
78 %CheckImportExportFunction(the_export, 1); | |
79 | |
80 })(); | |
81 | |
82 (function TestImportExportWrapperMoreParams() { | |
83 var second_module = new WasmModuleBuilder(); | |
84 var sig_index_3 = second_module.addType(kSig_v_iii); | |
85 second_module.addImportWithModule("js", "thePrint", sig_index_3); | |
86 second_module.addFunction("second_export", sig_index_3) | |
87 .addBody([ | |
88 kExprGetLocal, 0, | |
89 kExprGetLocal, 1, | |
90 kExprGetLocal, 2, | |
91 kExprCallImport, kArity3, 0 | |
92 ]) | |
93 .exportFunc(); | |
94 | |
95 var first_module = new WasmModuleBuilder(); | |
96 var sig_index_2 = first_module.addType(kSig_v_ii); | |
97 first_module.addImportWithModule("blah", "nothing", sig_index_2); | |
98 first_module.addFunction("export_fct", sig_index_2) | |
99 .addBody([ | |
100 kExprGetLocal, 0, | |
101 kExprGetLocal, 1, | |
102 kExprCallFunction, kArity2, 1 | |
103 ]) | |
104 .exportFunc(); | |
105 first_module.addFunction("increment", sig_index_2) | |
106 .addBody([ | |
107 kExprGetLocal, 0, | |
108 kExprGetLocal, 1, | |
109 kExprCallImport, kArity2, 0 | |
110 ]); | |
111 | |
112 var f = second_module.instantiate({js:{thePrint:print}}).exports.second_expo rt; | |
113 var the_export = first_module.instantiate({blah:{nothing:f}}).exports.export _fct; | |
114 | |
115 the_export(5, 4); | |
116 %CheckImportExportFunction(the_export, 1); | |
117 | |
118 })(); | |
119 | |
120 (function TestImportExportWrapperTypeMismatch() { | |
121 var second_module = new WasmModuleBuilder(); | |
122 var sig_index_2 = second_module.addType(kSig_v_dd); | |
123 second_module.addImportWithModule("js", "thePrint", sig_index_2); | |
124 second_module.addFunction("second_export", sig_index_2) | |
125 .addBody([ | |
126 kExprGetLocal, 0, | |
127 kExprGetLocal, 1, | |
128 kExprCallImport, kArity2, 0 | |
129 ]) | |
130 .exportFunc(); | |
131 | |
132 var first_module = new WasmModuleBuilder(); | |
133 var sig_index_2 = first_module.addType(kSig_v_ii); | |
134 first_module.addImportWithModule("blah", "nothing", sig_index_2); | |
135 first_module.addFunction("export_fct", sig_index_2) | |
136 .addBody([ | |
137 kExprGetLocal, 0, | |
138 kExprGetLocal, 1, | |
139 kExprCallFunction, kArity2, 1 | |
140 ]) | |
141 .exportFunc(); | |
142 first_module.addFunction("increment", sig_index_2) | |
143 .addBody([ | |
144 kExprGetLocal, 0, | |
145 kExprGetLocal, 1, | |
146 kExprCallImport, kArity2, 0 | |
147 ]); | |
148 | |
149 var f = second_module.instantiate({js:{thePrint:print}}).exports.second_expo rt; | |
150 var the_export = first_module.instantiate({blah:{nothing:f}}).exports.export _fct; | |
151 | |
152 the_export(6, 8); | |
153 %CheckImportExportFunction(the_export, 1); | |
154 })(); | |
OLD | NEW |