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 14 matching lines...) Expand all Loading... |
25 var expected = (i == offset) ? 151587081 : 0; | 25 var expected = (i == offset) ? 151587081 : 0; |
26 assertEquals(expected, instance.exports.load(i)); | 26 assertEquals(expected, instance.exports.load(i)); |
27 } | 27 } |
28 } | 28 } |
29 | 29 |
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 GlobalInitTest(offset) { | |
36 print("GlobalInitTest(" + offset + ")..."); | |
37 var builder = new WasmModuleBuilder(); | |
38 builder.addMemory(1, 1, false); | |
39 var g = builder.addGlobal(kAstI32, false); | |
40 g.init = offset; | |
41 builder.addFunction("load", kSig_i_i) | |
42 .addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0]) | |
43 .exportAs("load"); | |
44 builder.addDataSegment(g.index, [7, 7, 7, 7], true); | |
45 | |
46 var buffer = builder.toBuffer(debug); | |
47 var instance = new WebAssembly.Instance(new WebAssembly.Module(buffer)); | |
48 for (var i = offset - 20; i < offset + 20; i += 4) { | |
49 if (i < 0) continue; | |
50 var expected = i == offset ? 117901063 : 0; | |
51 assertEquals(expected, instance.exports.load(i)); | |
52 } | |
53 } | |
54 | |
55 GlobalInitTest(0); | |
56 GlobalInitTest(12); | |
57 GlobalInitTest(3040); | |
58 | |
59 function GlobalImportedInitTest(pad) { | 35 function GlobalImportedInitTest(pad) { |
60 print("GlobaleImportedInitTest(" + pad + ")..."); | 36 print("GlobaleImportedInitTest(" + pad + ")..."); |
61 var builder = new WasmModuleBuilder(); | 37 var builder = new WasmModuleBuilder(); |
62 builder.addMemory(1, 1, false); | 38 builder.addMemory(1, 1, false); |
63 | 39 |
64 while (pad-- > 0) builder.addGlobal(kAstI32); // pad | 40 while (pad-- > 0) builder.addGlobal(kAstI32); // pad |
65 | 41 |
66 var g = builder.addImportedGlobal("offset", undefined, kAstI32); | 42 var g = builder.addImportedGlobal("offset", undefined, kAstI32); |
67 | 43 |
68 while (pad-- > 0) builder.addGlobal(kAstI32); // pad | 44 while (pad-- > 0) builder.addGlobal(kAstI32); // pad |
(...skipping 12 matching lines...) Expand all Loading... |
81 if (i < 0) continue; | 57 if (i < 0) continue; |
82 var expected = i == offset ? 84215045 : 0; | 58 var expected = i == offset ? 84215045 : 0; |
83 assertEquals(expected, instance.exports.load(i)); | 59 assertEquals(expected, instance.exports.load(i)); |
84 } | 60 } |
85 } | 61 } |
86 } | 62 } |
87 | 63 |
88 GlobalImportedInitTest(0); | 64 GlobalImportedInitTest(0); |
89 GlobalImportedInitTest(1); | 65 GlobalImportedInitTest(1); |
90 GlobalImportedInitTest(4); | 66 GlobalImportedInitTest(4); |
OLD | NEW |