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 var debug = false; | 10 var debug = false; |
(...skipping 19 matching lines...) Expand all Loading... |
30 SimpleDataSegmentTest(0); | 30 SimpleDataSegmentTest(0); |
31 SimpleDataSegmentTest(4); | 31 SimpleDataSegmentTest(4); |
32 SimpleDataSegmentTest(12); | 32 SimpleDataSegmentTest(12); |
33 SimpleDataSegmentTest(1064); | 33 SimpleDataSegmentTest(1064); |
34 | 34 |
35 function GlobalImportedInitTest(pad) { | 35 function GlobalImportedInitTest(pad) { |
36 print("GlobaleImportedInitTest(" + pad + ")..."); | 36 print("GlobaleImportedInitTest(" + pad + ")..."); |
37 var builder = new WasmModuleBuilder(); | 37 var builder = new WasmModuleBuilder(); |
38 builder.addMemory(1, 1, false); | 38 builder.addMemory(1, 1, false); |
39 | 39 |
40 while (pad-- > 0) builder.addGlobal(kAstI32); // pad | 40 while (pad-- > 0) builder.addGlobal(kWasmI32); // pad |
41 | 41 |
42 var g = builder.addImportedGlobal("mod", "offset", kAstI32); | 42 var g = builder.addImportedGlobal("mod", "offset", kWasmI32); |
43 | 43 |
44 while (pad-- > 0) builder.addGlobal(kAstI32); // pad | 44 while (pad-- > 0) builder.addGlobal(kWasmI32); // pad |
45 | 45 |
46 builder.addFunction("load", kSig_i_i) | 46 builder.addFunction("load", kSig_i_i) |
47 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) | 47 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) |
48 .exportAs("load"); | 48 .exportAs("load"); |
49 builder.addDataSegment(g.index, [5, 5, 5, 5], true); | 49 builder.addDataSegment(g.index, [5, 5, 5, 5], true); |
50 | 50 |
51 var buffer = builder.toBuffer(debug); | 51 var buffer = builder.toBuffer(debug); |
52 var module = new WebAssembly.Module(buffer); | 52 var module = new WebAssembly.Module(buffer); |
53 | 53 |
54 for (var offset of [0, 12, 192, 1024]) { | 54 for (var offset of [0, 12, 192, 1024]) { |
55 var instance = new WebAssembly.Instance(module, {mod: {offset: offset}}); | 55 var instance = new WebAssembly.Instance(module, {mod: {offset: offset}}); |
56 for (var i = offset - 20; i < offset + 20; i += 4) { | 56 for (var i = offset - 20; i < offset + 20; i += 4) { |
57 if (i < 0) continue; | 57 if (i < 0) continue; |
58 var expected = i == offset ? 84215045 : 0; | 58 var expected = i == offset ? 84215045 : 0; |
59 assertEquals(expected, instance.exports.load(i)); | 59 assertEquals(expected, instance.exports.load(i)); |
60 } | 60 } |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 GlobalImportedInitTest(0); | 64 GlobalImportedInitTest(0); |
65 GlobalImportedInitTest(1); | 65 GlobalImportedInitTest(1); |
66 GlobalImportedInitTest(4); | 66 GlobalImportedInitTest(4); |
OLD | NEW |