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) { |
11 print("TestImported " + type + "(" + val +")" + " = " + expected); | 11 print("TestImported " + type + "(" + val +")" + " = " + expected); |
12 var builder = new WasmModuleBuilder(); | 12 var builder = new WasmModuleBuilder(); |
13 var sig = makeSig([], [type]); | 13 var sig = makeSig([], [type]); |
14 var g = builder.addImportedGlobal("uuu", "foo", type); | 14 var g = builder.addImportedGlobal("uuu", "foo", type); |
15 builder.addFunction("main", sig) | 15 builder.addFunction("main", sig) |
16 .addBody([kExprGetGlobal, g.index]) | 16 .addBody([kExprGetGlobal, g]) |
17 .exportAs("main"); | 17 .exportAs("main"); |
18 builder.addGlobal(kWasmI32); // pad | 18 builder.addGlobal(kWasmI32); // pad |
19 | 19 |
20 var instance = builder.instantiate({uuu: {foo: val}}); | 20 var instance = builder.instantiate({uuu: {foo: val}}); |
21 assertEquals(expected, instance.exports.main()); | 21 assertEquals(expected, instance.exports.main()); |
22 } | 22 } |
23 | 23 |
24 TestImported(kWasmI32, 300.1, 300); | 24 TestImported(kWasmI32, 300.1, 300); |
25 TestImported(kWasmF32, 87234.87238, Math.fround(87234.87238)); | 25 TestImported(kWasmF32, 87234.87238, Math.fround(87234.87238)); |
26 TestImported(kWasmF64, 77777.88888, 77777.88888); | 26 TestImported(kWasmF64, 77777.88888, 77777.88888); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 .addBody([kExprGetGlobal, def.index]) | 89 .addBody([kExprGetGlobal, def.index]) |
90 .exportAs("main"); | 90 .exportAs("main"); |
91 | 91 |
92 var instance = builder.instantiate({nnn: {foo: val}}); | 92 var instance = builder.instantiate({nnn: {foo: val}}); |
93 assertEquals(val, instance.exports.main()); | 93 assertEquals(val, instance.exports.main()); |
94 } | 94 } |
95 | 95 |
96 TestGlobalIndexSpace(kWasmI32, 123); | 96 TestGlobalIndexSpace(kWasmI32, 123); |
97 TestGlobalIndexSpace(kWasmF32, 54321.125); | 97 TestGlobalIndexSpace(kWasmF32, 54321.125); |
98 TestGlobalIndexSpace(kWasmF64, 12345.678); | 98 TestGlobalIndexSpace(kWasmF64, 12345.678); |
OLD | NEW |