OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 TestImported(type, val, expected) { | 10 function TestImported(type, val, expected) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 o.init_index = i; | 57 o.init_index = i; |
58 builder.addGlobal(kAstI32); // pad | 58 builder.addGlobal(kAstI32); // pad |
59 | 59 |
60 var instance = builder.instantiate({foo: val}); | 60 var instance = builder.instantiate({foo: val}); |
61 assertEquals(expected, instance.exports.bar); | 61 assertEquals(expected, instance.exports.bar); |
62 } | 62 } |
63 | 63 |
64 TestImportedExported(kAstI32, 415.5, 415); | 64 TestImportedExported(kAstI32, 415.5, 415); |
65 TestImportedExported(kAstF32, -979.34343, Math.fround(-979.34343)); | 65 TestImportedExported(kAstF32, -979.34343, Math.fround(-979.34343)); |
66 TestImportedExported(kAstF64, 81347.66666, 81347.66666); | 66 TestImportedExported(kAstF64, 81347.66666, 81347.66666); |
| 67 |
| 68 function TestGlobalIndexSpace(type, val) { |
| 69 print("TestGlobalIndexSpace(" + val + ") = " + val); |
| 70 var builder = new WasmModuleBuilder(); |
| 71 var im = builder.addImportedGlobal("foo", undefined, type); |
| 72 assertEquals(0, im); |
| 73 var def = builder.addGlobal(type, false); |
| 74 assertEquals(1, def.index); |
| 75 def.init_index = im; |
| 76 |
| 77 var sig = makeSig([], [type]); |
| 78 builder.addFunction("main", sig) |
| 79 .addBody([kExprGetGlobal, def.index]) |
| 80 .exportAs("main"); |
| 81 |
| 82 var instance = builder.instantiate({foo: val}); |
| 83 assertEquals(val, instance.exports.main()); |
| 84 } |
| 85 |
| 86 TestGlobalIndexSpace(kAstI32, 123); |
| 87 TestGlobalIndexSpace(kAstF32, 54321.125); |
| 88 TestGlobalIndexSpace(kAstF64, 12345.678); |
OLD | NEW |