OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 load("test/mjsunit/wasm/wasm-constants.js"); |
| 6 |
| 7 var module = (function () { |
| 8 var kFuncWithBody = 9; |
| 9 var kFuncImported = 7; |
| 10 var kBodySize1 = 5; |
| 11 var kBodySize2 = 8; |
| 12 var kFuncTableSize = 8; |
| 13 var kSubOffset = 13 + kFuncWithBody + kBodySize1 + kFuncImported + kFuncWithBo
dy + kBodySize2 + kFuncTableSize + 1; |
| 14 var kAddOffset = kSubOffset + 4; |
| 15 var kMainOffset = kAddOffset + 4; |
| 16 |
| 17 var ffi = new Object(); |
| 18 ffi.add = (function(a, b) { return a + b | 0; }); |
| 19 |
| 20 return WASM.instantiateModule(bytes( |
| 21 // -- signatures |
| 22 kDeclSignatures, 2, |
| 23 2, kAstI32, kAstI32, kAstI32, // int, int -> int |
| 24 3, kAstI32, kAstI32, kAstI32, kAstI32, // int, int, int -> int |
| 25 // -- function #0 (sub) |
| 26 kDeclFunctions, 3, |
| 27 kDeclFunctionName, |
| 28 0, 0, // signature offset |
| 29 kSubOffset, 0, 0, 0, // name offset |
| 30 kBodySize1, 0, // body size |
| 31 kExprI32Sub, // -- |
| 32 kExprGetLocal, 0, // -- |
| 33 kExprGetLocal, 1, // -- |
| 34 // -- function #1 (add) |
| 35 kDeclFunctionName | kDeclFunctionImport, |
| 36 0, 0, // signature offset |
| 37 kAddOffset, 0, 0, 0, // name offset |
| 38 // -- function #2 (main) |
| 39 kDeclFunctionName | kDeclFunctionExport, |
| 40 1, 0, // signature offset |
| 41 kMainOffset, 0, 0, 0, // name offset |
| 42 kBodySize2, 0, // body size |
| 43 kExprCallIndirect, 0, |
| 44 kExprGetLocal, 0, |
| 45 kExprGetLocal, 1, |
| 46 kExprGetLocal, 2, |
| 47 // -- function table |
| 48 kDeclFunctionTable, |
| 49 3, |
| 50 0, 0, |
| 51 1, 0, |
| 52 2, 0, |
| 53 kDeclEnd, |
| 54 's', 'u', 'b', 0, // name |
| 55 'a', 'd', 'd', 0, // name |
| 56 'm', 'a', 'i', 'n', 0 // name |
| 57 ), ffi); |
| 58 })(); |
| 59 |
| 60 // Check the module exists. |
| 61 assertFalse(module === undefined); |
| 62 assertFalse(module === null); |
| 63 assertFalse(module === 0); |
| 64 assertEquals("object", typeof module); |
| 65 assertEquals("function", typeof module.main); |
| 66 |
| 67 assertEquals(5, module.main(0, 12, 7)); |
| 68 assertEquals(19, module.main(1, 12, 7)); |
| 69 |
| 70 assertTraps(kTrapFuncSigMismatch, "module.main(2, 12, 33)"); |
| 71 assertTraps(kTrapFuncInvalid, "module.main(3, 12, 33)"); |
OLD | NEW |