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 testExportedMain() { | 10 (function testExportedMain() { |
11 var kReturnValue = 88; | 11 var kReturnValue = 88; |
12 var builder = new WasmModuleBuilder(); | 12 var builder = new WasmModuleBuilder(); |
13 | 13 |
14 builder.addFunction("main", [kAstI32]) | 14 builder.addFunction("main", [kAstI32]) |
15 .addBody([ | 15 .addBody([ |
16 kExprReturn, | |
17 kExprI8Const, | 16 kExprI8Const, |
18 kReturnValue]) | 17 kReturnValue, |
| 18 kExprReturn, kArity1 |
| 19 ]) |
19 .exportFunc(); | 20 .exportFunc(); |
20 | 21 |
21 var module = builder.instantiate(); | 22 var module = builder.instantiate(); |
22 | 23 |
23 assertEquals("object", typeof module.exports); | 24 assertEquals("object", typeof module.exports); |
24 assertEquals("function", typeof module.exports.main); | 25 assertEquals("function", typeof module.exports.main); |
25 | 26 |
26 assertEquals(kReturnValue, module.exports.main()); | 27 assertEquals(kReturnValue, module.exports.main()); |
27 })(); | 28 })(); |
28 | 29 |
29 (function testExportedTwice() { | 30 (function testExportedTwice() { |
30 var kReturnValue = 99; | 31 var kReturnValue = 99; |
31 | 32 |
32 var builder = new WasmModuleBuilder(); | 33 var builder = new WasmModuleBuilder(); |
33 | 34 |
34 builder.addFunction("main", [kAstI32]) | 35 builder.addFunction("main", [kAstI32]) |
35 .addBody([ | 36 .addBody([ |
36 kExprReturn, | |
37 kExprI8Const, | 37 kExprI8Const, |
38 kReturnValue]) | 38 kReturnValue, |
| 39 kExprReturn, kArity1 |
| 40 ]) |
39 .exportAs("blah") | 41 .exportAs("blah") |
40 .exportAs("foo"); | 42 .exportAs("foo"); |
41 | 43 |
42 var module = builder.instantiate(); | 44 var module = builder.instantiate(); |
43 | 45 |
44 assertEquals("object", typeof module.exports); | 46 assertEquals("object", typeof module.exports); |
45 assertEquals("function", typeof module.exports.blah); | 47 assertEquals("function", typeof module.exports.blah); |
46 assertEquals("function", typeof module.exports.foo); | 48 assertEquals("function", typeof module.exports.foo); |
47 | 49 |
48 assertEquals(kReturnValue, module.exports.foo()); | 50 assertEquals(kReturnValue, module.exports.foo()); |
49 assertEquals(kReturnValue, module.exports.blah()); | 51 assertEquals(kReturnValue, module.exports.blah()); |
50 })(); | 52 })(); |
OLD | NEW |