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 function assertModule(module, memsize) { | 10 function assertModule(module, memsize) { |
11 // Check the module exists. | 11 // Check the module exists. |
12 assertFalse(module === undefined); | 12 assertFalse(module === undefined); |
13 assertFalse(module === null); | 13 assertFalse(module === null); |
14 assertFalse(module === 0); | 14 assertFalse(module === 0); |
15 assertEquals("object", typeof module); | 15 assertEquals("object", typeof module); |
16 | 16 |
17 // Check the memory is an ArrayBuffer. | 17 // Check the memory is an ArrayBuffer. |
18 var mem = module.exports.memory; | 18 var mem = module.exports.memory; |
19 assertFalse(mem === undefined); | 19 assertFalse(mem === undefined); |
20 assertFalse(mem === null); | 20 assertFalse(mem === null); |
21 assertFalse(mem === 0); | 21 assertFalse(mem === 0); |
22 assertEquals("object", typeof mem); | 22 assertEquals("object", typeof mem); |
23 assertTrue(mem instanceof WebAssembly.Memory); | 23 assertTrue(mem instanceof ArrayBuffer); |
24 var buf = mem.buffer; | |
25 assertTrue(buf instanceof ArrayBuffer); | |
26 assertEquals(memsize, buf.byteLength); | |
27 for (var i = 0; i < 4; i++) { | 24 for (var i = 0; i < 4; i++) { |
28 module.exports.memory = 0; // should be ignored | 25 module.exports.memory = 0; // should be ignored |
29 mem.buffer = 0; // should be ignored | 26 assertEquals(mem, module.exports.memory); |
30 assertSame(mem, module.exports.memory); | |
31 assertSame(buf, mem.buffer); | |
32 } | 27 } |
| 28 |
| 29 assertEquals(memsize, module.exports.memory.byteLength); |
33 } | 30 } |
34 | 31 |
35 function assertFunction(module, func) { | 32 function assertFunction(module, func) { |
36 assertEquals("object", typeof module.exports); | 33 assertEquals("object", typeof module.exports); |
37 | 34 |
38 var exp = module.exports[func]; | 35 var exp = module.exports[func]; |
39 assertFalse(exp === undefined); | 36 assertFalse(exp === undefined); |
40 assertFalse(exp === null); | 37 assertFalse(exp === null); |
41 assertFalse(exp === 0); | 38 assertFalse(exp === 0); |
42 assertEquals("function", typeof exp); | 39 assertEquals("function", typeof exp); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 .exportFunc(); | 96 .exportFunc(); |
100 | 97 |
101 var module = builder.instantiate(); | 98 var module = builder.instantiate(); |
102 assertModule(module, kPageSize * kPages); | 99 assertModule(module, kPageSize * kPages); |
103 | 100 |
104 var flt = assertFunction(module, "flt"); | 101 var flt = assertFunction(module, "flt"); |
105 assertEquals(1, flt(-2, -1)); | 102 assertEquals(1, flt(-2, -1)); |
106 assertEquals(0, flt(7.3, 7.1)); | 103 assertEquals(0, flt(7.3, 7.1)); |
107 assertEquals(1, flt(7.1, 7.3)); | 104 assertEquals(1, flt(7.1, 7.3)); |
108 })(); | 105 })(); |
OLD | NEW |