| 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) { | |
| 11 // Check the module exists. | |
| 12 assertFalse(module === undefined); | |
| 13 assertFalse(module === null); | |
| 14 assertFalse(module === 0); | |
| 15 assertEquals("object", typeof module); | |
| 16 | |
| 17 // Check the memory is an ArrayBuffer. | |
| 18 var mem = module.exports.memory; | |
| 19 assertFalse(mem === undefined); | |
| 20 assertFalse(mem === null); | |
| 21 assertFalse(mem === 0); | |
| 22 assertEquals("object", typeof mem); | |
| 23 assertTrue(mem instanceof ArrayBuffer); | |
| 24 for (var i = 0; i < 4; i++) { | |
| 25 module.exports.memory = 0; // should be ignored | |
| 26 assertEquals(mem, module.exports.memory); | |
| 27 } | |
| 28 | |
| 29 assertEquals(memsize, module.exports.memory.byteLength); | |
| 30 } | |
| 31 | |
| 32 function assertFunction(module, func) { | |
| 33 assertEquals("object", typeof module.exports); | |
| 34 | |
| 35 var exp = module.exports[func]; | |
| 36 assertFalse(exp === undefined); | |
| 37 assertFalse(exp === null); | |
| 38 assertFalse(exp === 0); | |
| 39 assertEquals("function", typeof exp); | |
| 40 return exp; | |
| 41 } | |
| 42 | |
| 43 (function I64SubTest() { | 10 (function I64SubTest() { |
| 44 | 11 |
| 45 var builder = new WasmModuleBuilder(); | 12 var builder = new WasmModuleBuilder(); |
| 46 | 13 |
| 47 builder.addMemory(1, 1, true); | 14 builder.addMemory(1, 1, true); |
| 48 builder.addFunction("sub", kSig_l_ll) | 15 builder.addFunction("sub", kSig_l_ll) |
| 49 .addBody([ // -- | 16 .addBody([ // -- |
| 50 kExprGetLocal, 0, // -- | 17 kExprGetLocal, 0, // -- |
| 51 kExprGetLocal, 1, // -- | 18 kExprGetLocal, 1, // -- |
| 52 kExprI64Sub]) // -- | 19 kExprI64Sub]) // -- |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 .exportFunc(); | 85 .exportFunc(); |
| 119 | 86 |
| 120 var module = builder.instantiate(); | 87 var module = builder.instantiate(); |
| 121 assertModule(module, kPageSize * kPages); | 88 assertModule(module, kPageSize * kPages); |
| 122 | 89 |
| 123 var flt = assertFunction(module, "flt"); | 90 var flt = assertFunction(module, "flt"); |
| 124 assertEquals(1, flt(-2, -1)); | 91 assertEquals(1, flt(-2, -1)); |
| 125 assertEquals(0, flt(7.3, 7.1)); | 92 assertEquals(0, flt(7.3, 7.1)); |
| 126 assertEquals(1, flt(7.1, 7.3)); | 93 assertEquals(1, flt(7.1, 7.3)); |
| 127 })(); | 94 })(); |
| OLD | NEW |