OLD | NEW |
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 --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 function testCallFFI(func, check) { | 10 function testCallFFI(func, check) { |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 passed_length = arguments.length; | 235 passed_length = arguments.length; |
236 passed_a = a; | 236 passed_a = a; |
237 passed_b = b; | 237 passed_b = b; |
238 args_a = arguments[0]; | 238 args_a = arguments[0]; |
239 args_b = arguments[1]; | 239 args_b = arguments[1]; |
240 }}}; | 240 }}}; |
241 | 241 |
242 var builder = new WasmModuleBuilder(); | 242 var builder = new WasmModuleBuilder(); |
243 | 243 |
244 builder.addImport("", "func", makeSig_v_xx(type)); | 244 builder.addImport("", "func", makeSig_v_xx(type)); |
245 builder.addFunction("main", makeSig_r_xx(kAstI32, type)) | 245 builder.addFunction("main", makeSig_r_xx(kWasmI32, type)) |
246 .addBody([ | 246 .addBody([ |
247 kExprGetLocal, 0, // -- | 247 kExprGetLocal, 0, // -- |
248 kExprGetLocal, 1, // -- | 248 kExprGetLocal, 1, // -- |
249 kExprCallFunction, 0, // -- | 249 kExprCallFunction, 0, // -- |
250 kExprI8Const, 99 // -- | 250 kExprI8Const, 99 // -- |
251 ]) // -- | 251 ]) // -- |
252 .exportFunc() | 252 .exportFunc() |
253 | 253 |
254 var main = builder.instantiate(ffi).exports.main; | 254 var main = builder.instantiate(ffi).exports.main; |
255 | 255 |
256 print("testCallBinopVoid", type); | 256 print("testCallBinopVoid", type); |
257 | 257 |
258 for (var i = 0; i < 100000; i += 10003.1) { | 258 for (var i = 0; i < 100000; i += 10003.1) { |
259 var a = 22.5 + i, b = 10.5 + i; | 259 var a = 22.5 + i, b = 10.5 + i; |
260 var r = main(a, b); | 260 var r = main(a, b); |
261 assertEquals(99, r); | 261 assertEquals(99, r); |
262 assertEquals(2, passed_length); | 262 assertEquals(2, passed_length); |
263 var expected_a, expected_b; | 263 var expected_a, expected_b; |
264 switch (type) { | 264 switch (type) { |
265 case kAstI32: { | 265 case kWasmI32: { |
266 expected_a = a | 0; | 266 expected_a = a | 0; |
267 expected_b = b | 0; | 267 expected_b = b | 0; |
268 break; | 268 break; |
269 } | 269 } |
270 case kAstF32: { | 270 case kWasmF32: { |
271 expected_a = Math.fround(a); | 271 expected_a = Math.fround(a); |
272 expected_b = Math.fround(b); | 272 expected_b = Math.fround(b); |
273 break; | 273 break; |
274 } | 274 } |
275 case kAstF64: { | 275 case kWasmF64: { |
276 expected_a = a; | 276 expected_a = a; |
277 expected_b = b; | 277 expected_b = b; |
278 break; | 278 break; |
279 } | 279 } |
280 } | 280 } |
281 | 281 |
282 assertEquals(expected_a, args_a); | 282 assertEquals(expected_a, args_a); |
283 assertEquals(expected_b, args_b); | 283 assertEquals(expected_b, args_b); |
284 assertEquals(expected_a, passed_a); | 284 assertEquals(expected_a, passed_a); |
285 assertEquals(expected_b, passed_b); | 285 assertEquals(expected_b, passed_b); |
286 } | 286 } |
287 } | 287 } |
288 | 288 |
289 | 289 |
290 testCallBinopVoid(kAstI32); | 290 testCallBinopVoid(kWasmI32); |
291 // TODO testCallBinopVoid(kAstI64); | 291 // TODO testCallBinopVoid(kWasmI64); |
292 testCallBinopVoid(kAstF32); | 292 testCallBinopVoid(kWasmF32); |
293 testCallBinopVoid(kAstF64); | 293 testCallBinopVoid(kWasmF64); |
294 | 294 |
295 (function testCallPrint() { | 295 (function testCallPrint() { |
296 var builder = new WasmModuleBuilder(); | 296 var builder = new WasmModuleBuilder(); |
297 | 297 |
298 builder.addImport("", "print", makeSig_v_x(kAstI32)); | 298 builder.addImport("", "print", makeSig_v_x(kWasmI32)); |
299 builder.addImport("", "print", makeSig_v_x(kAstF64)); | 299 builder.addImport("", "print", makeSig_v_x(kWasmF64)); |
300 builder.addFunction("main", makeSig_v_x(kAstF64)) | 300 builder.addFunction("main", makeSig_v_x(kWasmF64)) |
301 .addBody([ | 301 .addBody([ |
302 kExprI8Const, 97, // -- | 302 kExprI8Const, 97, // -- |
303 kExprCallFunction, 0, // -- | 303 kExprCallFunction, 0, // -- |
304 kExprGetLocal, 0, // -- | 304 kExprGetLocal, 0, // -- |
305 kExprCallFunction, 1 // -- | 305 kExprCallFunction, 1 // -- |
306 ]) // -- | 306 ]) // -- |
307 .exportFunc() | 307 .exportFunc() |
308 | 308 |
309 var main = builder.instantiate({"": {print: print}}).exports.main; | 309 var main = builder.instantiate({"": {print: print}}).exports.main; |
310 for (var i = -9; i < 900; i += 6.125) main(i); | 310 for (var i = -9; i < 900; i += 6.125) main(i); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 .exportFunc(); | 378 .exportFunc(); |
379 var num_valueOf = 0; | 379 var num_valueOf = 0; |
380 function Foo() {} | 380 function Foo() {} |
381 Foo.prototype.valueOf = () => ++num_valueOf; | 381 Foo.prototype.valueOf = () => ++num_valueOf; |
382 var func = () => new Foo(); | 382 var func = () => new Foo(); |
383 var main = builder.instantiate({"": {func: func}}).exports.main; | 383 var main = builder.instantiate({"": {func: func}}).exports.main; |
384 main(); | 384 main(); |
385 main(); | 385 main(); |
386 assertEquals(0, num_valueOf); | 386 assertEquals(0, num_valueOf); |
387 })(); | 387 })(); |
OLD | NEW |