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 load("test/mjsunit/wasm/wasm-module-builder.js"); | 8 load("test/mjsunit/wasm/wasm-module-builder.js"); |
9 | 9 |
10 var kReturnValue = 117; | 10 var kReturnValue = 117; |
11 | 11 |
12 var module = (function Build() { | 12 var module = (function Build() { |
13 var builder = new WasmModuleBuilder(); | 13 var builder = new WasmModuleBuilder(); |
14 | 14 |
15 builder.addMemory(1, 1, true); | 15 builder.addMemory(1, 1, true); |
16 builder.addFunction("main", [kAstI32]) | 16 builder.addFunction("main", [kAstI32]) |
17 .addBody([kExprI8Const, kReturnValue]) | 17 .addBody([kExprI8Const, kReturnValue]) |
18 .exportFunc(); | 18 .exportFunc(); |
19 | 19 |
20 return builder.instantiate(); | 20 return builder.instantiate(); |
21 })(); | 21 })(); |
22 | 22 |
23 // Check the module exists. | 23 // Check the module exists. |
24 assertFalse(module === undefined); | 24 assertFalse(module === undefined); |
25 assertFalse(module === null); | 25 assertFalse(module === null); |
26 assertFalse(module === 0); | 26 assertFalse(module === 0); |
27 assertEquals("object", typeof module); | 27 assertEquals("object", typeof module); |
28 | 28 |
29 // Check the memory is an ArrayBuffer. | 29 // Check the memory is an ArrayBuffer. |
30 var mem = module.memory; | 30 var mem = module.exports.memory; |
31 assertFalse(mem === undefined); | 31 assertFalse(mem === undefined); |
32 assertFalse(mem === null); | 32 assertFalse(mem === null); |
33 assertFalse(mem === 0); | 33 assertFalse(mem === 0); |
34 assertEquals("object", typeof mem); | 34 assertEquals("object", typeof mem); |
35 assertTrue(mem instanceof ArrayBuffer); | 35 assertTrue(mem instanceof ArrayBuffer); |
36 for (var i = 0; i < 4; i++) { | 36 for (var i = 0; i < 4; i++) { |
37 module.memory = 0; // should be ignored | 37 module.exports.memory = 0; // should be ignored |
38 assertEquals(mem, module.memory); | 38 assertEquals(mem, module.exports.memory); |
39 } | 39 } |
40 | 40 |
41 assertEquals(65536, module.memory.byteLength); | 41 assertEquals(65536, module.exports.memory.byteLength); |
42 | 42 |
43 // Check the properties of the main function. | 43 // Check the properties of the main function. |
44 var main = module.exports.main; | 44 var main = module.exports.main; |
45 assertFalse(main === undefined); | 45 assertFalse(main === undefined); |
46 assertFalse(main === null); | 46 assertFalse(main === null); |
47 assertFalse(main === 0); | 47 assertFalse(main === 0); |
48 assertEquals("function", typeof main); | 48 assertEquals("function", typeof main); |
49 | 49 |
50 assertEquals(kReturnValue, main()); | 50 assertEquals(kReturnValue, main()); |
OLD | NEW |