OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --expose-wasm |
| 6 |
| 7 load("test/mjsunit/wasm/wasm-constants.js"); |
| 8 |
| 9 (function testExportedMain() { |
| 10 var kBodySize = 3; |
| 11 var kReturnValue = 99; |
| 12 var kNameMainOffset = 4 + 7 + kBodySize + 8 + 1; |
| 13 |
| 14 var data = bytes( |
| 15 // signatures |
| 16 kDeclSignatures, 1, |
| 17 0, kAstI32, // void -> i32 |
| 18 // -- main function |
| 19 kDeclFunctions, |
| 20 1, |
| 21 0, // decl flags |
| 22 0, 0, // signature index |
| 23 kBodySize, 0, |
| 24 // main body |
| 25 kExprReturn, |
| 26 kExprI8Const, |
| 27 kReturnValue, |
| 28 // exports |
| 29 kDeclExportTable, |
| 30 1, |
| 31 0, 0, // func index index |
| 32 kNameMainOffset, 0, 0, 0, // function name offset |
| 33 // names |
| 34 kDeclEnd, |
| 35 'm', 'a', 'i', 'n', 0 // -- |
| 36 ); |
| 37 |
| 38 var ffi = new Object(); |
| 39 var module = _WASMEXP_.instantiateModule(data, ffi); |
| 40 |
| 41 assertEquals("object", typeof module.exports); |
| 42 assertEquals("function", typeof module.exports.main); |
| 43 |
| 44 assertEquals(kReturnValue, module.exports.main()); |
| 45 })(); |
| 46 |
| 47 (function testExportedTwice() { |
| 48 var kBodySize = 3; |
| 49 var kReturnValue = 99; |
| 50 var kNameMainOffset = 4 + 7 + kBodySize + 14 + 1; |
| 51 var kNameFooOffset = kNameMainOffset + 5; |
| 52 |
| 53 var data = bytes( |
| 54 // signatures |
| 55 kDeclSignatures, 1, |
| 56 0, kAstI32, // void -> i32 |
| 57 // -- main function |
| 58 kDeclFunctions, |
| 59 1, |
| 60 0, // decl flags |
| 61 0, 0, // signature index |
| 62 kBodySize, 0, |
| 63 // main body |
| 64 kExprReturn, |
| 65 kExprI8Const, |
| 66 kReturnValue, |
| 67 // exports |
| 68 kDeclExportTable, |
| 69 2, |
| 70 0, 0, // func index index |
| 71 kNameMainOffset, 0, 0, 0, // function name offset |
| 72 0, 0, // func index index |
| 73 kNameFooOffset, 0, 0, 0, // function name offset |
| 74 // names |
| 75 kDeclEnd, |
| 76 'b', 'l', 'a', 'h', 0, // -- |
| 77 'f', 'o', 'o', 0 // -- |
| 78 ); |
| 79 |
| 80 var ffi = new Object(); |
| 81 var module = _WASMEXP_.instantiateModule(data, ffi); |
| 82 |
| 83 assertEquals("object", typeof module.exports); |
| 84 assertEquals("function", typeof module.exports.blah); |
| 85 assertEquals("function", typeof module.exports.foo); |
| 86 |
| 87 assertEquals(kReturnValue, module.exports.blah()); |
| 88 assertEquals(kReturnValue, module.exports.foo()); |
| 89 })(); |
OLD | NEW |