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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(kWasmI32, 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 kExprI32Const, 33 // -- |
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(33, 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 kWasmI32: { | 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 kWasmF32: { | 270 case kWasmF32: { |
271 expected_a = Math.fround(a); | 271 expected_a = Math.fround(a); |
(...skipping 20 matching lines...) Expand all Loading... |
292 testCallBinopVoid(kWasmF32); | 292 testCallBinopVoid(kWasmF32); |
293 testCallBinopVoid(kWasmF64); | 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(kWasmI32)); | 298 builder.addImport("", "print", makeSig_v_x(kWasmI32)); |
299 builder.addImport("", "print", makeSig_v_x(kWasmF64)); | 299 builder.addImport("", "print", makeSig_v_x(kWasmF64)); |
300 builder.addFunction("main", makeSig_v_x(kWasmF64)) | 300 builder.addFunction("main", makeSig_v_x(kWasmF64)) |
301 .addBody([ | 301 .addBody([ |
302 kExprI8Const, 97, // -- | 302 kExprI32Const, 37, // -- |
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); |
311 })(); | 311 })(); |
312 | 312 |
(...skipping 65 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 |