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 --expose-gc --stress-compaction | 5 // Flags: --expose-wasm --expose-gc --stress-compaction |
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 kMemSize = 65536; | 10 var kMemSize = 65536; |
(...skipping 20 matching lines...) Expand all Loading... |
31 /* */ kExprI32Sub, // -- | 31 /* */ kExprI32Sub, // -- |
32 /* */ kExprSetLocal, 0, // -- | 32 /* */ kExprSetLocal, 0, // -- |
33 /* */ kExprBr, 1, // -- | 33 /* */ kExprBr, 1, // -- |
34 /* */ kExprEnd, // -- | 34 /* */ kExprEnd, // -- |
35 /* */ kExprEnd, // -- | 35 /* */ kExprEnd, // -- |
36 /**/ kExprI8Const, 0 // -- | 36 /**/ kExprI8Const, 0 // -- |
37 ]) | 37 ]) |
38 .exportFunc(); | 38 .exportFunc(); |
39 var module = builder.instantiate(null, memory); | 39 var module = builder.instantiate(null, memory); |
40 assertTrue(module.exports.memory instanceof WebAssembly.Memory); | 40 assertTrue(module.exports.memory instanceof WebAssembly.Memory); |
41 if (memory != null) assertEquals(memory, module.exports.memory.buffer); | 41 if (memory != null) assertEquals(memory.buffer, module.exports.memory.buffer); |
42 return module; | 42 return module; |
43 } | 43 } |
44 | 44 |
45 function testPokeMemory() { | 45 function testPokeMemory() { |
| 46 print("testPokeMemory"); |
46 var module = genModule(null); | 47 var module = genModule(null); |
47 var buffer = module.exports.memory.buffer; | 48 var buffer = module.exports.memory.buffer; |
48 var main = module.exports.main; | 49 var main = module.exports.main; |
49 assertEquals(kMemSize, buffer.byteLength); | 50 assertEquals(kMemSize, buffer.byteLength); |
50 | 51 |
51 var array = new Int8Array(buffer); | 52 var array = new Int8Array(buffer); |
52 assertEquals(kMemSize, array.length); | 53 assertEquals(kMemSize, array.length); |
53 | 54 |
54 for (var i = 0; i < kMemSize; i++) { | 55 for (var i = 0; i < kMemSize; i++) { |
55 assertEquals(0, array[i]); | 56 assertEquals(0, array[i]); |
(...skipping 26 matching lines...) Expand all Loading... |
82 } | 83 } |
83 } | 84 } |
84 | 85 |
85 testSurvivalAcrossGc(); | 86 testSurvivalAcrossGc(); |
86 testSurvivalAcrossGc(); | 87 testSurvivalAcrossGc(); |
87 testSurvivalAcrossGc(); | 88 testSurvivalAcrossGc(); |
88 testSurvivalAcrossGc(); | 89 testSurvivalAcrossGc(); |
89 | 90 |
90 | 91 |
91 function testPokeOuterMemory() { | 92 function testPokeOuterMemory() { |
92 var buffer = new ArrayBuffer(kMemSize); | 93 print("testPokeOuterMemory"); |
| 94 var buffer = new WebAssembly.Memory({initial: kMemSize / kPageSize}); |
93 var module = genModule(buffer); | 95 var module = genModule(buffer); |
94 var main = module.exports.main; | 96 var main = module.exports.main; |
95 assertEquals(kMemSize, buffer.byteLength); | 97 assertEquals(kMemSize, buffer.buffer.byteLength); |
96 | 98 |
97 var array = new Int8Array(buffer); | 99 var array = new Int8Array(buffer.buffer); |
98 assertEquals(kMemSize, array.length); | 100 assertEquals(kMemSize, array.length); |
99 | 101 |
100 for (var i = 0; i < kMemSize; i++) { | 102 for (var i = 0; i < kMemSize; i++) { |
101 assertEquals(0, array[i]); | 103 assertEquals(0, array[i]); |
102 } | 104 } |
103 | 105 |
104 for (var i = 0; i < 10; i++) { | 106 for (var i = 0; i < 10; i++) { |
105 assertEquals(0, main(kMemSize - 4)); | 107 assertEquals(0, main(kMemSize - 4)); |
106 | 108 |
107 array[kMemSize/2 + i] = 1; | 109 array[kMemSize/2 + i] = 1; |
108 assertEquals(0, main(kMemSize/2 - 4)); | 110 assertEquals(0, main(kMemSize/2 - 4)); |
109 assertEquals(-1, main(kMemSize - 4)); | 111 assertEquals(-1, main(kMemSize - 4)); |
110 | 112 |
111 array[kMemSize/2 + i] = 0; | 113 array[kMemSize/2 + i] = 0; |
112 assertEquals(0, main(kMemSize - 4)); | 114 assertEquals(0, main(kMemSize - 4)); |
113 } | 115 } |
114 } | 116 } |
115 | 117 |
116 testPokeOuterMemory(); | 118 testPokeOuterMemory(); |
117 | 119 |
118 function testOuterMemorySurvivalAcrossGc() { | 120 function testOuterMemorySurvivalAcrossGc() { |
119 var buffer = new ArrayBuffer(kMemSize); | 121 var buffer = new WebAssembly.Memory({initial: kMemSize / kPageSize}); |
120 var checker = genAndGetMain(buffer); | 122 var checker = genAndGetMain(buffer); |
121 for (var i = 0; i < 3; i++) { | 123 for (var i = 0; i < 3; i++) { |
122 print("gc run ", i); | 124 print("gc run ", i); |
123 assertEquals(0, checker(kMemSize - 4)); | 125 assertEquals(0, checker(kMemSize - 4)); |
124 gc(); | 126 gc(); |
125 } | 127 } |
126 } | 128 } |
127 | 129 |
128 testOuterMemorySurvivalAcrossGc(); | 130 testOuterMemorySurvivalAcrossGc(); |
129 testOuterMemorySurvivalAcrossGc(); | 131 testOuterMemorySurvivalAcrossGc(); |
(...skipping 28 matching lines...) Expand all Loading... |
158 } | 160 } |
159 | 161 |
160 | 162 |
161 for (offset = 65534; offset < 66536; offset++) { | 163 for (offset = 65534; offset < 66536; offset++) { |
162 assertTraps(kTrapMemOutOfBounds, read); | 164 assertTraps(kTrapMemOutOfBounds, read); |
163 assertTraps(kTrapMemOutOfBounds, write); | 165 assertTraps(kTrapMemOutOfBounds, write); |
164 } | 166 } |
165 } | 167 } |
166 | 168 |
167 testOOBThrows(); | 169 testOOBThrows(); |
OLD | NEW |