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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 builder.addImportWithModule('18', '-3', kSig_v_i); | 331 builder.addImportWithModule('18', '-3', kSig_v_i); |
332 builder.addImportWithModule('-3', '18', kSig_v_i); | 332 builder.addImportWithModule('-3', '18', kSig_v_i); |
333 | 333 |
334 builder.instantiate({ | 334 builder.instantiate({ |
335 foo: {0: print}, | 335 foo: {0: print}, |
336 0: {0: print, foo: print}, | 336 0: {0: print, foo: print}, |
337 18: {'-3': print}, | 337 18: {'-3': print}, |
338 '-3': {18: print} | 338 '-3': {18: print} |
339 }); | 339 }); |
340 })(); | 340 })(); |
| 341 |
| 342 (function ImportSymbolAsVoidDoesNotThrow() { |
| 343 var builder = new WasmModuleBuilder(); |
| 344 // Return type is void, so there should be no ToNumber conversion. |
| 345 var index = builder.addImport("func", kSig_v_v); |
| 346 builder.addFunction("main", kSig_v_v) |
| 347 .addBody([kExprCallFunction, 0]) |
| 348 .exportFunc(); |
| 349 var func = () => Symbol(); |
| 350 var main = builder.instantiate({func: func}).exports.main; |
| 351 main(); |
| 352 })(); |
| 353 |
| 354 (function ToNumberCalledOnImport() { |
| 355 var builder = new WasmModuleBuilder(); |
| 356 // Return type is int, so there should be a ToNumber conversion. |
| 357 var index = builder.addImport("func", kSig_i_v); |
| 358 builder.addFunction("main", kSig_i_v) |
| 359 .addBody([kExprCallFunction, 0]) |
| 360 .exportFunc(); |
| 361 var num_valueOf = 0; |
| 362 function Foo() {} |
| 363 Foo.prototype.valueOf = () => ++num_valueOf; |
| 364 var func = () => new Foo(); |
| 365 var main = builder.instantiate({func: func}).exports.main; |
| 366 main(); |
| 367 assertEquals(1, num_valueOf); |
| 368 main(); |
| 369 assertEquals(2, num_valueOf); |
| 370 })(); |
| 371 |
| 372 (function ToNumberNotCalledOnVoidImport() { |
| 373 var builder = new WasmModuleBuilder(); |
| 374 // Return type is void, so there should be no ToNumber conversion. |
| 375 var index = builder.addImport("func", kSig_v_v); |
| 376 builder.addFunction("main", kSig_v_v) |
| 377 .addBody([kExprCallFunction, 0]) |
| 378 .exportFunc(); |
| 379 var num_valueOf = 0; |
| 380 function Foo() {} |
| 381 Foo.prototype.valueOf = () => ++num_valueOf; |
| 382 var func = () => new Foo(); |
| 383 var main = builder.instantiate({func: func}).exports.main; |
| 384 main(); |
| 385 main(); |
| 386 assertEquals(0, num_valueOf); |
| 387 })(); |
OLD | NEW |