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 | 5 // Flags: --expose-wasm |
6 | 6 |
7 load("test/mjsunit/wasm/wasm-constants.js"); | 7 load("test/mjsunit/wasm/wasm-constants.js"); |
8 | 8 |
9 var module = (function () { | 9 var module = (function () { |
10 var kFuncWithBody = 9; | 10 var kFuncWithBody = 9; |
11 var kFuncImported = 7; | 11 var kFuncImported = 7; |
12 var kBodySize1 = 5; | 12 var kBodySize1 = 5; |
13 var kBodySize2 = 8; | 13 var kBodySize2 = 8; |
14 var kFuncTableSize = 8; | 14 var kFuncTableSize = 8; |
15 var kSubOffset = 13 + kFuncWithBody + kBodySize1 + kFuncImported + kFuncWithBo
dy + kBodySize2 + kFuncTableSize + 1; | 15 var kSubOffset = kHeaderSize + 13 + kFuncWithBody + kBodySize1 + kFuncImported
+ kFuncWithBody + kBodySize2 + kFuncTableSize + 1; |
16 var kAddOffset = kSubOffset + 4; | 16 var kAddOffset = kSubOffset + 4; |
17 var kMainOffset = kAddOffset + 4; | 17 var kMainOffset = kAddOffset + 4; |
18 | 18 |
19 var ffi = new Object(); | 19 var ffi = new Object(); |
20 ffi.add = (function(a, b) { return a + b | 0; }); | 20 ffi.add = (function(a, b) { return a + b | 0; }); |
21 | 21 |
22 return _WASMEXP_.instantiateModule(bytes( | 22 return _WASMEXP_.instantiateModule(bytesWithHeader( |
23 // -- signatures | 23 // -- signatures |
24 kDeclSignatures, 2, | 24 kDeclSignatures, 2, |
25 2, kAstI32, kAstI32, kAstI32, // int, int -> int | 25 2, kAstI32, kAstI32, kAstI32, // int, int -> int |
26 3, kAstI32, kAstI32, kAstI32, kAstI32, // int, int, int -> int | 26 3, kAstI32, kAstI32, kAstI32, kAstI32, // int, int, int -> int |
27 // -- function #0 (sub) | 27 // -- function #0 (sub) |
28 kDeclFunctions, 3, | 28 kDeclFunctions, 3, |
29 kDeclFunctionName, | 29 kDeclFunctionName, |
30 0, 0, // signature offset | 30 0, 0, // signature offset |
31 kSubOffset, 0, 0, 0, // name offset | 31 kSubOffset, 0, 0, 0, // name offset |
32 kBodySize1, 0, // body size | 32 kBodySize1, 0, // body size |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 assertFalse(module === null); | 64 assertFalse(module === null); |
65 assertFalse(module === 0); | 65 assertFalse(module === 0); |
66 assertEquals("object", typeof module); | 66 assertEquals("object", typeof module); |
67 assertEquals("function", typeof module.main); | 67 assertEquals("function", typeof module.main); |
68 | 68 |
69 assertEquals(5, module.main(0, 12, 7)); | 69 assertEquals(5, module.main(0, 12, 7)); |
70 assertEquals(19, module.main(1, 12, 7)); | 70 assertEquals(19, module.main(1, 12, 7)); |
71 | 71 |
72 assertTraps(kTrapFuncSigMismatch, "module.main(2, 12, 33)"); | 72 assertTraps(kTrapFuncSigMismatch, "module.main(2, 12, 33)"); |
73 assertTraps(kTrapFuncInvalid, "module.main(3, 12, 33)"); | 73 assertTraps(kTrapFuncInvalid, "module.main(3, 12, 33)"); |
OLD | NEW |