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