OLD | NEW |
(Empty) | |
| 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 load("test/mjsunit/wasm/wasm-constants.js"); |
| 6 |
| 7 var kReturnValue = 117; |
| 8 |
| 9 var kBodySize = 2; |
| 10 var kNameOffset = 19 + kBodySize + 1; |
| 11 |
| 12 var data = bytes( |
| 13 // -- memory |
| 14 kDeclMemory, |
| 15 10, 10, 1, |
| 16 // -- signatures |
| 17 kDeclSignatures, 1, |
| 18 0, kAstI32, // signature: void -> int |
| 19 // -- main function |
| 20 kDeclFunctions, 1, |
| 21 kDeclFunctionName | kDeclFunctionExport, |
| 22 0, 0, // signature index |
| 23 kNameOffset, 0, 0, 0, // name offset |
| 24 kBodySize, 0, // body size |
| 25 // -- body |
| 26 kExprI8Const, // -- |
| 27 kReturnValue, // -- |
| 28 kDeclEnd, |
| 29 'm', 'a', 'i', 'n', 0 // name |
| 30 ); |
| 31 |
| 32 var module = WASM.instantiateModule(data); |
| 33 |
| 34 // Check the module exists. |
| 35 assertFalse(module === undefined); |
| 36 assertFalse(module === null); |
| 37 assertFalse(module === 0); |
| 38 assertEquals("object", typeof module); |
| 39 |
| 40 // Check the memory is an ArrayBuffer. |
| 41 var mem = module.memory; |
| 42 assertFalse(mem === undefined); |
| 43 assertFalse(mem === null); |
| 44 assertFalse(mem === 0); |
| 45 assertEquals("object", typeof mem); |
| 46 assertTrue(mem instanceof ArrayBuffer); |
| 47 for (var i = 0; i < 4; i++) { |
| 48 module.memory = 0; // should be ignored |
| 49 assertEquals(mem, module.memory); |
| 50 } |
| 51 |
| 52 assertEquals(1024, module.memory.byteLength); |
| 53 |
| 54 // Check the properties of the main function. |
| 55 assertFalse(module.main === undefined); |
| 56 assertFalse(module.main === null); |
| 57 assertFalse(module.main === 0); |
| 58 assertEquals("function", typeof module.main); |
| 59 |
| 60 assertEquals(kReturnValue, module.main()); |
OLD | NEW |