OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 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, expected, a, b) { | 10 function testCallImport(func, expected, a, b) { |
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("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 kExprCallImport, 2, 0]) // -- |
20 .exportAs("main"); | 20 .exportAs("main"); |
21 | 21 |
22 var main = builder.instantiate({func: func}).exports.main; | 22 var main = builder.instantiate({func: func}).exports.main; |
23 | 23 |
24 assertEquals(expected, main(a, b)); | 24 assertEquals(expected, main(a, b)); |
25 } | 25 } |
26 | 26 |
27 var global = (function() { return this; })(); | 27 var global = (function() { return this; })(); |
28 | 28 |
29 function sloppyReceiver(a, b) { | 29 function sloppyReceiver(a, b) { |
30 assertEquals(global, this); | 30 assertEquals(global, this); |
31 assertEquals(33.3, a); | 31 assertEquals(33.3, a); |
32 assertEquals(44.4, b); | 32 assertEquals(44.4, b); |
33 return 11; | 33 return 11; |
34 } | 34 } |
35 | 35 |
36 function strictReceiver(a, b) { | 36 function strictReceiver(a, b) { |
37 'use strict'; | 37 'use strict'; |
38 assertEquals(undefined, this); | 38 assertEquals(undefined, this); |
39 assertEquals(55.5, a); | 39 assertEquals(55.5, a); |
40 assertEquals(66.6, b); | 40 assertEquals(66.6, b); |
41 return 22; | 41 return 22; |
42 } | 42 } |
43 | 43 |
44 testCallImport(sloppyReceiver, 11, 33.3, 44.4); | 44 testCallImport(sloppyReceiver, 11, 33.3, 44.4); |
45 testCallImport(strictReceiver, 22, 55.5, 66.6); | 45 testCallImport(strictReceiver, 22, 55.5, 66.6); |
OLD | NEW |