OLD | NEW |
| (Empty) |
1 // Copyright 2015 the V8 project authors. All rights reserved. | |
2 // | |
3 // Use of this source code is governed by a BSD-style license that can be | |
4 // found in the LICENSE file. | |
5 | |
6 // Flags: --expose-wasm | |
7 // Flags: --wasm-jit-prototype | |
8 | |
9 load("test/mjsunit/wasm/wasm-constants.js"); | |
10 load("test/mjsunit/wasm/wasm-module-builder.js"); | |
11 | |
12 var module = (function () { | |
13 var builder = new WasmModuleBuilder(); | |
14 | |
15 var sig_index = builder.addType(kSig_i_ii); | |
16 builder.addPadFunctionTable(512); | |
17 builder.addImport("add", sig_index); | |
18 builder.addFunction("add", sig_index) | |
19 .addBody([ | |
20 kExprGetLocal, 0, kExprGetLocal, 1, kExprCallImport, kArity2, 0 | |
21 ]); | |
22 builder.addFunction("sub", sig_index) | |
23 .addBody([ | |
24 kExprGetLocal, 0, // -- | |
25 kExprGetLocal, 1, // -- | |
26 kExprI32Sub, // -- | |
27 ]); | |
28 builder.addFunction("main", kSig_i_iii) | |
29 .addBody([ | |
30 kExprGetLocal, 0, | |
31 kExprGetLocal, 1, | |
32 kExprGetLocal, 2, | |
33 kExprCallIndirect, kArity2, sig_index | |
34 ]) | |
35 .exportFunc() | |
36 builder.appendToTable([0, 1, 2]); | |
37 | |
38 return builder.instantiate({add: function(a, b) { return a + b | 0; }}); | |
39 })(); | |
40 | |
41 // Check the module exists. | |
42 assertFalse(module === undefined); | |
43 assertFalse(module === null); | |
44 assertFalse(module === 0); | |
45 assertEquals("object", typeof module.exports); | |
46 assertEquals("function", typeof module.exports.main); | |
47 | |
48 assertEquals(5, module.exports.main(1, 12, 7)); | |
49 assertEquals(19, module.exports.main(0, 12, 7)); | |
50 | |
51 assertTraps(kTrapFuncSigMismatch, "module.exports.main(2, 12, 33)"); | |
52 assertTraps(kTrapFuncSigMismatch, "module.exports.main(4, 12, 33)"); | |
53 assertTraps(kTrapFuncSigMismatch, "module.exports.main(511, 12, 33)"); | |
54 assertTraps(kTrapFuncInvalid, "module.exports.main(512, 12, 33)"); | |
55 assertTraps(kTrapFuncInvalid, "module.exports.main(1025, 12, 33)"); | |
56 assertTraps(kTrapFuncInvalid, "module.exports.main(-1, 12, 33)"); | |
OLD | NEW |