Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: test/mjsunit/wasm/import-table.js

Issue 2591753002: [wasm] Implement correct 2-level namespace for imports. (Closed)
Patch Set: Fix debug tests Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/wasm/import-memory.js ('k') | test/mjsunit/wasm/indirect-calls.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 5 // Flags: --expose-wasm
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 function testCallImport(func, check) { 10 function testCallImport(func, check) {
11 var builder = new WasmModuleBuilder(); 11 var builder = new WasmModuleBuilder();
12 12
13 var sig_index = builder.addType(kSig_i_dd); 13 var sig_index = builder.addType(kSig_i_dd);
14 builder.addImport("func", sig_index); 14 builder.addImport("q", "func", sig_index);
15 builder.addFunction("main", sig_index) 15 builder.addFunction("main", sig_index)
16 .addBody([ 16 .addBody([
17 kExprGetLocal, 0, // -- 17 kExprGetLocal, 0, // --
18 kExprGetLocal, 1, // -- 18 kExprGetLocal, 1, // --
19 kExprCallFunction, 0]) // -- 19 kExprCallFunction, 0]) // --
20 .exportAs("main"); 20 .exportAs("main");
21 21
22 var main = builder.instantiate({func: func}).exports.main; 22 var main = builder.instantiate({q: {func: func}}).exports.main;
23 23
24 for (var i = 0; i < 100000; i += 10003) { 24 for (var i = 0; i < 100000; i += 10003) {
25 var a = 22.5 + i, b = 10.5 + i; 25 var a = 22.5 + i, b = 10.5 + i;
26 var r = main(a, b); 26 var r = main(a, b);
27 check(r, a, b); 27 check(r, a, b);
28 } 28 }
29 } 29 }
30 30
31 var global = (function() { return this; })(); 31 var global = (function() { return this; })();
32 var params = [-99, -99, -99, -99]; 32 var params = [-99, -99, -99, -99];
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 testCallImport(returnValue(null), checkReturn(0)); 161 testCallImport(returnValue(null), checkReturn(0));
162 testCallImport(returnValue("0"), checkReturn(0)); 162 testCallImport(returnValue("0"), checkReturn(0));
163 testCallImport(returnValue("-77"), checkReturn(-77)); 163 testCallImport(returnValue("-77"), checkReturn(-77));
164 164
165 var objWithValueOf = {valueOf: function() { return 198; }} 165 var objWithValueOf = {valueOf: function() { return 198; }}
166 166
167 testCallImport(returnValue(objWithValueOf), checkReturn(198)); 167 testCallImport(returnValue(objWithValueOf), checkReturn(198));
168 168
169 169
170 function testCallBinopVoid(type, func, check) { 170 function testCallBinopVoid(type, func, check) {
171 var ffi = new Object();
172
173 var passed_length = -1; 171 var passed_length = -1;
174 var passed_a = -1; 172 var passed_a = -1;
175 var passed_b = -1; 173 var passed_b = -1;
176 var args_a = -1; 174 var args_a = -1;
177 var args_b = -1; 175 var args_b = -1;
178 176
179 ffi.func = function(a, b) { 177 var ffi = {q: {func: function(a, b) {
180 passed_length = arguments.length; 178 passed_length = arguments.length;
181 passed_a = a; 179 passed_a = a;
182 passed_b = b; 180 passed_b = b;
183 args_a = arguments[0]; 181 args_a = arguments[0];
184 args_b = arguments[1]; 182 args_b = arguments[1];
185 } 183 }}};
186 184
187 var builder = new WasmModuleBuilder(); 185 var builder = new WasmModuleBuilder();
188 186
189 builder.addImport("func", makeSig_v_xx(type)); 187 builder.addImport("q", "func", makeSig_v_xx(type));
190 builder.addFunction("main", makeSig_r_xx(kAstI32, type)) 188 builder.addFunction("main", makeSig_r_xx(kAstI32, type))
191 .addBody([ 189 .addBody([
192 kExprGetLocal, 0, // -- 190 kExprGetLocal, 0, // --
193 kExprGetLocal, 1, // -- 191 kExprGetLocal, 1, // --
194 kExprCallFunction, 0, // -- 192 kExprCallFunction, 0, // --
195 kExprI8Const, 99, // -- 193 kExprI8Const, 99, // --
196 ]) 194 ])
197 .exportFunc("main"); 195 .exportFunc("main");
198 196
199 var main = builder.instantiate(ffi).exports.main; 197 var main = builder.instantiate(ffi).exports.main;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 232
235 testCallBinopVoid(kAstI32); 233 testCallBinopVoid(kAstI32);
236 // TODO testCallBinopVoid(kAstI64); 234 // TODO testCallBinopVoid(kAstI64);
237 testCallBinopVoid(kAstF32); 235 testCallBinopVoid(kAstF32);
238 testCallBinopVoid(kAstF64); 236 testCallBinopVoid(kAstF64);
239 237
240 238
241 239
242 function testCallPrint() { 240 function testCallPrint() {
243 var builder = new WasmModuleBuilder(); 241 var builder = new WasmModuleBuilder();
244 builder.addImport("print", makeSig_v_x(kAstI32)); 242 builder.addImport("q", "print", makeSig_v_x(kAstI32));
245 builder.addImport("print", makeSig_r_x(kAstF64, kAstF64)); 243 builder.addImport("q", "print", makeSig_r_x(kAstF64, kAstF64));
246 builder.addFunction("main", makeSig_r_x(kAstF64, kAstF64)) 244 builder.addFunction("main", makeSig_r_x(kAstF64, kAstF64))
247 .addBody([ 245 .addBody([
248 kExprI8Const, 97, // -- 246 kExprI8Const, 97, // --
249 kExprCallFunction, 0, // -- 247 kExprCallFunction, 0, // --
250 kExprGetLocal, 0, // -- 248 kExprGetLocal, 0, // --
251 kExprCallFunction, 1 // -- 249 kExprCallFunction, 1 // --
252 ]) 250 ])
253 .exportFunc(); 251 .exportFunc();
254 252
255 var main = builder.instantiate({print: print}).exports.main; 253 var main = builder.instantiate({q: {print: print}}).exports.main;
256 254
257 for (var i = -9; i < 900; i += 16.125) { 255 for (var i = -9; i < 900; i += 16.125) {
258 main(i); 256 main(i);
259 } 257 }
260 } 258 }
261 259
262 testCallPrint(); 260 testCallPrint();
263 testCallPrint(); 261 testCallPrint();
264 262
265 263
266 function testCallImport2(foo, bar, expected) { 264 function testCallImport2(foo, bar, expected) {
267 var builder = new WasmModuleBuilder(); 265 var builder = new WasmModuleBuilder();
268 266
269 builder.addImport("foo", kSig_i_v); 267 builder.addImport("q", "foo", kSig_i_v);
270 builder.addImport("bar", kSig_i_v); 268 builder.addImport("t", "bar", kSig_i_v);
271 builder.addFunction("main", kSig_i_v) 269 builder.addFunction("main", kSig_i_v)
272 .addBody([ 270 .addBody([
273 kExprCallFunction, 0, // -- 271 kExprCallFunction, 0, // --
274 kExprCallFunction, 1, // -- 272 kExprCallFunction, 1, // --
275 kExprI32Add, // -- 273 kExprI32Add, // --
276 ]) // -- 274 ]) // --
277 .exportFunc(); 275 .exportFunc();
278 276
279 var main = builder.instantiate({foo: foo, bar: bar}).exports.main; 277 var main = builder.instantiate({q: {foo: foo}, t: {bar: bar}}).exports.main;
280 assertEquals(expected, main()); 278 assertEquals(expected, main());
281 } 279 }
282 280
283 testCallImport2(function() { return 33; }, function () { return 44; }, 77); 281 testCallImport2(function() { return 33; }, function () { return 44; }, 77);
284 282
285 283
286 function testImportName(name) { 284 function testImportName(name) {
287 var builder = new WasmModuleBuilder(); 285 var builder = new WasmModuleBuilder();
288 builder.addImportWithModule("M", name, kSig_i_v); 286 builder.addImport("M", name, kSig_i_v);
289 builder.addFunction("main", kSig_i_v) 287 builder.addFunction("main", kSig_i_v)
290 .addBody([ 288 .addBody([
291 kExprCallFunction, 0 289 kExprCallFunction, 0
292 ]) 290 ])
293 .exportFunc(); 291 .exportFunc();
294 292
295 let main = builder.instantiate({M: {[name]: () => 42}}).exports.main; 293 let main = builder.instantiate({M: {[name]: () => 42}}).exports.main;
296 assertEquals(42, main()); 294 assertEquals(42, main());
297 } 295 }
298 296
299 testImportName("bla"); 297 testImportName("bla");
300 testImportName("0"); 298 testImportName("0");
301 testImportName(" a @#$2 324 "); 299 testImportName(" a @#$2 324 ");
302 // TODO(bradnelson): This should succeed. 300 // TODO(bradnelson): This should succeed.
303 // testImportName(""); 301 // testImportName("");
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/import-memory.js ('k') | test/mjsunit/wasm/indirect-calls.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698